I have a problem understanding one thing in C. I read in "ANSI C" that expressions such as a[n], where ais an array are really equivalent *(a+n). So, here is a small piece of code that I wrote to verify that:
#include <stdio.h>
int main(void)
{
int a[10] = {0,1,2,3,4,5,6,7,8,9};
int *p = a;
printf("sizeof a: %d\n", sizeof(a));
printf("sizeof p: %d\n", sizeof(p));
return 0;
}
After executing the code, the program produces:
sizeof a: 40
sizeof p: 8
I do not understand - what have I just done? How aand pdifferent objects? (Judging by the output of the sizeof function)
source
share