int sampleArray[] = {1,2,3,4,5};
I understand that the sampleArray
now points to the first element of the array.
However, what does it mean when I say &sampleArray
? Does it mean I am getting the address of the sampleArray
variable? Or does it mean a two-dimensional array variable?
So, can I do this:
int (*p)[5] = &sampleArray?
No, sampleArray
does not really point to the first element of the array. sampleArray
is the array.
The confusion arises because in most places where you use sampleArray
, it will be replaced with a pointer to the first element of the array. "Most places" means "anywhere that it isn't the operand of the sizeof
or unary-&
operators".
Since sampleArray
is the array itself, and being the operand of unary-&
is one of the places where it maintains that personality, this means that &sampleArray
is a pointer to the whole array.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With