【发布时间】:2017-03-13 07:16:12
【问题描述】:
为什么我的代码错误?
int *x ;
x = new int[5];
x[0] = 3;
x[1] = 4;
x[2] = 5;
x[3] = 1;
x[4] = 2;
x[5] = 11;
x[6] = 90;
int *y ;
y = new int[5];
cout << "if no error, then this command should be run" << endl;
但输出是:
进程在 0.07883 秒后退出,返回值 3221226356
按任意键继续。 . .
【问题讨论】:
-
new int [5]并分配7值......问题出在哪里......??? ;) -
C++ 没有边界检查。越界会导致未定义的行为。故事结束。