I am trying to code for Spiral Matrix where the input is a 2D array. When trying to simulate the code using double pointer i get 'Access Violation Reading' exception. Referred couple of links and tried different syntax but exception is not resolved. link 1 link 2
This is the exact code snippet which is throwing exception when debugging in VS2015.
void SpiralMatrix(int **arr, int row, int col)
{
int u = 0, l = 0, r = col-1, d = row - 1;
int val = arr[0][0];// *(*(arr + 0) + 0); // Throwing exception at this location
printf("%d",val);
}
int main()
{
int arr[2][3] = { {1,2,3},{4,5,6} };
SpiralMatrix((int **)arr,2,3);
}
I am really getting confused what am i missing here? I am trying to understand the root cause rather than the solution.