简体   繁体   中英

what does the sizeof(&a[0]) mean for an array 'a' of int?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM