First, there is no way to keep track of an array's size in C++ (only the amount of memory allocated). So, it is necessary that the size
of the array be passed as a parameter or be global. I make this assumption in the following declaration:
int* SubMatrix(int** matrix, int size){
int* submatrix = new int[(size - 1) * (size - 1)];
// Do stuff
return submatrix;
}
Second, if your matrix is square it may be better to use the declaration described above where the size of the array allocated is (N-1)*(N-1)
(See Kevin Loney's answer How do I declare a 2d array in C++ using new? regarding matrix declaration on a heap); thus, the array is accessible as a matrix. Accessing cells will, however, require a bit of arithmetic:
for (int i = 0; i < size - 1; ++i)
for (int j = 0; j < size - 1; ++j)
submatrix[i * (size -1) + j] // Element at [i][j]
Finally, the array returned by the function is now a matrix pointer:
int* matrix = SubMatrix(matrix, size);
The dimensions of the matrix returned are (size-1)*(size-1)
With respect to your example now:
x = {{1,2,3},{1,2,3},{1,2,3}};
int* y = SubMatrix(matrix, 3);
// y is now a matrix of size (size-1)*(size-1)
If you really (really) want a two-dimensional array:
int** SubMatrix(int** matrix, int size){
int** submatrix = new int*[size - 1];
for (int i = 0; i < size - 1; ++i)
submatrix[i] = new int[size - 1]
// Do stuff
return submatrix;
}