![](/img/trans.png)
[英]Run-Time Check Failure #2 - Stack around the variable ''z" was corrupted
[英]Run-Time Check Failure #2 - Stack around the variable 'ap' was corrupted
當我在Visual C ++ 2010 Express中運行少量代碼時,遇到了上述問題。
當我使用CodeBlocks時,由於(A)行,內部for
循環無法完全執行。
不知道為什么。 感謝幫助!
int main()
{
int* ap[10];
for(int j=0;j<10;j++){
*(ap+j) = new int[10];
for(int i=0;i<10;i++){
*((ap+j)+i) = *(ap+j)+i;//(A)
**((ap+j)+i) = j * 10 + i;
cout<<setw(6)<<**((ap+j)+i);
}
cout<<endl;
}
return 0;
}
這條線
*((ap+j)+i) = *(ap+j)+i;//(A)
可以改寫成
ap[j+i] = ap[j]+i;//(A)
並且您可以清楚地看到,當j + i> 10時,這可以寫越界。
您可能是指ap[j][i]
或等效地*(*(ap+j)+i)
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.