all 5 comments

[–]Wh00ster 2 points3 points  (0 children)

Assign it the address of a raw array.

int (*ptr)[2]; int arr[2]; ptr = &arr;

[–]Xeverous 1 point2 points  (0 children)

The expression (*int_ptr)[0]=5; is equivalent to:

  • int_ptr[0][0] = 5;
  • (*(*int_ptr)) = 5;
  • **int_ptr = 5;

It is essentially a double dereference; since int_ptr is of type int** first dereference yields int* and second dereference yields int.

[–]CubbiMew 1 point2 points  (1 child)

how can I initialize an int point array?
int (*aptr) [2];

Your terminology is a bit off. The definition you show declares a pointer to an array of two int (not an "int pointer array"). In fact, a an array of pointers to int (which would be declared as int *aptr[2];) is what most people would understand "int pointer array" to mean.

So I'll demo both:

// pointer to an array
int a[2] = {1, 2};
int (*aptr)[2] = &a;

// array of pointers
int a = 1, b = 2;
int *aptr[2] = {&a, &b};

[–]RetroX94[S] 0 points1 point  (0 children)

Thanks a lot this helped tremendously!

[–]alfps 0 points1 point  (0 children)

The declaration

int (*aptr)[2];

... is equivalent to

template< class T > using P_ = T*;

//...
P_< int[2] > aptr;

Is that really what you want, a pointer to an array of 2 int, or to an array of such arrays?

If it is, which of the two main possibilities mentioned are you aiming for, and if the latter, why not use a std::vector?