void f(int **a)
{
cout << a[0][0] << endl;
cout << a[1][0] << endl;
}
int main()
{
{
int t1[2];
int tt[2][2];
tt[0][0] = 1;
tt[0][1] = 2;
tt[1][0] = 3;
tt[1][1] = 4;
int **ttp = new int*[2];
for(int i = 0; i < 2; ++i)
{
ttp[i] = new int[2];
for(int j = 0; j < 2; ++j)
{
ttp[i][j] = tt[i][j];
}
}
// 此处强转,在f中访问[0][0]元素时会出错。
// 传入ttp则是好的。
// 错误提示:test.exe 中的 0x00ee17bd 处有未经处理的异常: 0xC0000005: 读取位置 0x00000001 时发生访问冲突
f((int**)tt);
}
return 0;
慕盖茨4494581
RISEBY
幕布斯6054654
随时随地看视频慕课网APP
相关分类