I know that in C++, the name of an array is just the pointer to the first element of the array. For example:
int foo[5];
=> foo is a pointer of type int, and it points to the first element in the array, which is a[0]
But then, we have this:
int (*foo)[5]
Here, foo is a pointer to an array of type. So is foo a pointer to a pointer (of type int)?
That’s not correct: a name of an array can be converted to a corresponding pointer type “for free”, but it is definitely not a pointer. The easiest way you can tell is by comparing sizes of a pointer and of an array:
Your second example is a pointer to an array of
ints of size 5.In a 32-bit environment this prints
4and20, as expected.