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,
sampleArraydoes not really point to the first element of the array.sampleArrayis 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 thesizeofor unary-&operators”.Since
sampleArrayis the array itself, and being the operand of unary-&is one of the places where it maintains that personality, this means that&sampleArrayis a pointer to the whole array.