Here I have a pointer ptr
to array arr
of 4 integers. ptr
points to the whole array. ptr[0]
or *ptr
points to the first element of the array, so adding 1 to ptr[0]
gives the address of the second element of the array.
I can't understand why using sizeof(ptr[0])
gives the size of the whole array, 16 bytes, not the size of only the first element, 4 bytes, (as ptr[0]
points to the first element in the array).
int arr[4] = {0, 1, 2, 3};
int (*ptr)[4] = &arr;
printf("%zd", sizeof(ptr[0])); //output is 16