so if i run this code it will give the expected answer of 9
int main()
{
int a[]={9,8,7,6,5,4,3,2,1};
int n=sizeof(a)/sizeof(a[0]); printf("%d", n);
}
but if i change sizeof(a[0])
to sizeof(&a[0])
..then the output is 4
Why does this happen? Exactly what does the computer 'think' when it is given sizeof(&a[0])
?
&a[0]
on an array a
in C yields the address of its first element. On a 16-bit system, sizeof
of that address is most likely 2, on a 32-bit system, sizeof
that address it is 4, and, on a 64-bit system, it is 8.