从双指针读取访问冲突

时间:2016-12-28 02:22:03

标签: c++ arrays pointers

我正在尝试为Spiral Matrix编写代码,其中输入是2D数组。当尝试使用双指针模拟代码时,我得到了“访问违规读取”#39;例外。引用了几个链接并尝试了不同的语法,但异常未解决。 link 1 link 2

这是在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);
}

我真的很困惑我在这里失踪了什么?我试图理解根本原因而不是解决方案。

0 个答案:

没有答案
相关问题