I am writing a function to rotate a NxN matrix by 90 degree.
Here is my function
// "matrix" is an n by n matrix
void rotateMatrix(int ** matrix, int n)
{
for(int layer=0; layer < n; layer++)
{
int first = layer, last = n - layer -1;
for(int i=0; i<n; i++)
{
int temp = matrix[i][last];
matrix[i][last] = matrix[first][i];
matrix[first][i] = matrix[i][first];
matrix[i][first] = matrix[last][i];
matrix[last][i]=temp;
}
}
}
Here is how I initialize and call the function in main function:
int m[5][5] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25};
rotateMatrix(m,5);
What I got from my IDE is:
> error: cannot convert ‘int (*)[5]’ to
> ‘int**’ for argument ‘1’ to ‘void
> rotateMatrix(int**, int)’
I kinda know why it's wrong since "m" is a int* . However, I am not sure I can I solve this problem?