-3

Say, I define an array:

int a[5];

And

a = &a[0];

is an address to the beginning of the array.

My question is, does a get stored someplace in memory like a pointer variable? If so, when I try to print the address of a (&a), why do I get the same value as a?

cadaniluk
  • 15,027
  • 2
  • 39
  • 67

1 Answers1

1

When you declare an array, the only storage that gets set aside is for the array elements themselves; no storage is set aside for a pointer to the first element.

When the compiler sees an array expression that isn't the operand of the sizeof or & operators, or isn't a string literal being used to initialize another array in a declaration, it will convert that array expression to a pointer expression, and the value of the pointer expression will be the address of the first element in the array.

John Bode
  • 119,563
  • 19
  • 122
  • 198