Note that if a
is an array name, then sizeof(a)
will yields the size of the entire array a
and not the size of a pointer to one of its elements.
So for example, how does sizeof
distinguish an array a
and a pointer b
?
#include <stdio.h>
#include <stdlib.h>
int main(void) {
int a[4] = {1, 2, 3, 4};
int *b = a;
printf("sizeof\(a) = %ld\n", sizeof(a));
printf("sizeof\(b) = %ld\n", sizeof(b));
return EXIT_SUCCESS;
}
It prints as below:
sizeof(a) = 16
sizeof(b) = 8