I'm trying to figure out exactly how the relationship works between arrays and pointers in C++. I have read a number of threads and I feel as if it's just not sticking. Looking at this short bit of code here:
int studentAge[5];
int *p = &studentAge[0];
I've read that the reference operator(&) creates an exception to the array->pointer decay rule. So, from what I've read I believe they're saying that &studentAge
is technically a pointer to 5 integer values, not a pointer to a single integer. To elaborate more, is it right to say that its type will be int(*)[5]
, which cannot convert to int*
?
If it's a pointer to 5 integer values, then wouldn't that mean that it did, in fact, decay to a pointer? Or am I completely wrong in thinking this?
Furthermore, with this line of code:
p = studentAge;
Without the reference operator does the studentAge array now decay to a pointer? I apologize if I'm all over the place with this, but as I stated before, I'm having a difficult time getting 100% clear on this.