I think you should be able to use Dpp as you use arr.
Nope. Dpp is a pointer to a pointer to a
single int. arr is a one-dimensional array of 3 elements where each element is an array of 10 int.
Since the name of the array is the address of element 0, arr is the address of an array of 10 int. The address of an array of 10 int is not the same thing as a pointer to a pointer to a single int.
More info:
First, there are only one-dimensional arrays in C or C++. The number of elements in put between brackets:
That is an array of 5 elements each of which is an int.
won't compile. You need to declare the number of elements.
Second, this array:
is still an array of 5 elements. Each element is an array of 10 int.
is still an array of 5 elements. Each element is an array of 10 elements where each element is an array of 15 int.
won't compile. You need to declare the number of elements.
Third, the name of an array is the address of element 0
Here
array is the address of array[0]. Since array[0] is an int,
array is the address of an int. You can assign the name
array to an int*.
Here
array is the address of array[0]. Since array[0] is an array of 10 int,
array is the address of an array of 10 int. You can assign the name
array to a pointer to an array of 10 int:
-
int array[5][10];
-
-
int (*ptr)[10] = array;
-
Fourth, when the number of elements is not known at compile time, you create the array dynamically:
-
int* array = new int[value][5];
-
int (*ptr)[10] = new int[value][10];
-
int (*ptr)[10][15] = new int[value][10][15];
-
In each case
value is the
number of elements. Any other brackets only describe the elements.
Using an int** for an array of arrays is incorrect and produces wrong answers using pointer arithmetic. The compiler knows this so it won't compile this code:
-
int** ptr = new int[value][10]; //ERROR
-
new returns the address of an array of 10 int and that isn't the same as an int**.
Likewise:
-
int*** ptr = new int[value][10][15]; //ERROR
-
new returns the address of an array of 10 elements where each element is an array of 15 int and that isn't the same as an int***.