Array pointer increment

I am 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 this is not obvious, then what I was trying to do was find a pointer to the end of the array using pointer arithmetic.

Until now, I understand that it phas a pointer to an array type of ten integers, as well as an expression ++p. Usually I can assign an array of ints to a variable of type pointer to int, but that did not work with the pointer ++p.

At first I tried without static_cast, but that didn't work either.

+4
source share
1 answer

p has a pointer to an array of ten ints

It is right.

ints to int

. , , : p ints, ints. , .

, , , ( ), :

int *q = static_cast<int *>(*++p);
+7

Source: https://habr.com/ru/post/1668128/


All Articles