Sorry if this may seem like a stupid question, however, ive been working through C++ Primer, and I feel as if something hasn't been explained clearly...
(PS ints are just a generic example)
I understand what it means to have a array of pointers to ints e.g.
int *foo ;
int *foo1 ;
int (*p)  = ia;
When you declare a variable like
the type of the variable
int; that is, an array of 137
ints. In C++, you can create pointers or references to variables of any type that you'd like, so you can create a pointer to the variable
array has type "array of 137
ints," a pointer to
array would have type "pointer to an array of 137
ints." The syntax for writing out a pointer like this would be
int (*arrayPtr) = &array;
This is read as "
arrayPtr is a pointer, and what it points at is an array of 137
ints." The syntax here is unusual, but that's what you would do if you wanted a pointer to an array of 137 integers.
Similarly, you could make a reference to
array like this:
int (&arrayRef) = array;
It's extremely uncommon to see pointers to arrays actually used anywhere - I've never seen it done except in very specialized template circumstances. References to arrays are sometimes used in template programming, but otherwise I've never seen them used anywhere before.
In other words, it's good to know these exist and know how to read them, but realistically you're unlikely to need them unless you start doing some pretty advanced library development or like to play around with template wizardry.
This gets weirder when you factor array-to-pointer decay into the mix. The example code you had was essentially
int myArray; int (*arrayPtr) = myArray;
The type of
arrayPtr is "pointer to an array of 42
ints", which is of type
int (*) . So why can we assign
myArray, which has type
int, to it? This is where array-to-pointer decay kicks in. Array-to-pointer decay is an implicit conversion that converts an array to a pointer to its first element. Let's see how that applies here.
myArray is an array of 137 arrays of 42 integers. This can be though of as "an array of 137 things, each of which is an
int." This means that when array-to-pointer decay applies to
myArray, it converts to a pointer to its first element. That element is itself an array of 42 integers, so the effect of applying the array-to-pointer decay is that the expression
myArray implicitly converts to an
int (*)  (a pointer to an array of 42 integers), specifically, one pointing at the first row in the array.
The net effect of this assignment is that
arrayPtr now points to the first of the 137 arrays in
myArray. This is just plain weird, if you ask me, and I would not advise writing code like this. I've been writing C++ for years and never had the misfortune of seeing this used anywhere, so I think it's safe to chalk this one up to "bizarre edge cases that only library implementers need to worry about." :-)