I'm trying to understand why the following C++ code does not compile
int main () {
int a[10];
int (*p)[10] = &a;
int *q = static_cast<int *>(++p);
}
If it's not obvious, what I was trying to do is find a pointer to the end of the array by using pointer arithmetic.
My understanding so far is that p has type pointer to array of ten ints and so does the expression ++p. Normally, I can assign an array of ints to a variable of type pointer to int but this fails on the incremented pointer ++p.
I first tried without the static_cast but that didn't work either.
panint*:int* p = a; int* q = ++p;qto point to the end of the array. In that case you could doint *q = a + 10;. Alternatively, with C++11,int* q = std::end(a);(just include<iterator>).