Search code examples
csizeof

Sizeof &a vs *a


I searched thoroughly but could not find the solution to this: Assuming sizeof(int) = 4, we define:

int a[10] = {0};

What is the output of the following:
1. sizeof(&a)
2. sizeof(*a)
3. sizeof(a)

I know that sizeof(a) is equal to sizeof(int) * 10 = 40.
I also understand that *a is actually a the first element in the array, therefore sizeof(*a) is actually size of the int which resides in there, i.e. 4.

However, after running the code, I do not understand why size of &a is 8. I know that the '&' operator returns the address of the variable a, but why the sizeof the address is 8?


Solution

  • The size of the address depends on your architecture and is not directly related to the size of an int itself. So it’s 8 in your case, which seems pretty normal (64 bits).