how to assign two dimensional array to **pointer ? this is the idea of what i want to do
int arrray [2][3];
int **pointer = array;
so pointer[0][1]= 1;
so any help ? thanks in advance
Declare the pointer like this:
int (*pointer)[3] = array;
But this is infinitely nasty in C++. Perhaps you could find a better solution (one involving vectors and whatnot) if you explained what your general purpose is.
The simple answer is that you cannot. A bidimensional array is a contiguous block of memory that holds each line, while a pointer to pointer can refer to a memory location where a pointer to a different memory location containing the integers is.
You can on the other hand create a separate data structure that holds the pointers to the elements in the way you want (i.e. create an array of pointers, initialize those pointers to the beginning of each row, and use a pointer to that array of pointers as pointer
), but it is not useful at all, but rather will complicate everything unneedingly.
The question probably comes from the common misconceptions that arrays and pointers are the same, which they are not. An array can decay to a pointer to the first element of the array (and will do so quite often), but the type of that pointer is the type of the first element. In a bidimensional array, the type of the first element is the inner array, not the basic element type.