i have a doubt regarding sizeof operator
Code 1:
int main()
{
int p[10];
printf("%d",sizeof(p)); //output -- 40
return 0;
}
Code 2:
int main()
{
int *p[10];
printf("%d",sizeof(*p)); //output -- 4
return 0;
}
in the first code p points to an array of ints.
in the second code p points to an array of pointers.
i am not able to understand why the first code o/p is 40 but 2nd code o/p is 4 thought both points to an array of the same size ?
The output of the following program will give you some hints and understanding about the size of a type and a pointer to a type.
Now coming to your question:
You are correct. In the code:2, to get the size of the array where p points to, you need to pass the base address
and not the following
The following are equivalent:
The following is the answer to your other question: