In C++ when I perform the following action,
int* b = new int[5];
new int[5];
returns an int*
which I use b
to point to.
However, when performing,
int** c = new int[5][10];
I receive an error, cannot convert ‘int (*)[10]’ to ‘int**’ in initialization
.
Why does this syntax not work, however it will in other situations such as,
int** matrix = new int* [5];
for(int i=0; i < d1; i++){
matrix[i] = new int[10];
}
In the above example, matrix
is a pointer to an array which contains 5 elements of type int *
, therefore is int** c = new int[5][10];
not accomplishing the same thing? I am creating c
, a pointer to an array of 5 elements of type int *
, therefore the type should be int**
?
My question I guess is simply, why would int** c = new int[5][10];
throw me a cannot convert ‘int (*)[10]’ to ‘int**’ in initialization
but it works in the other example provided?