#include <iostream>
using std::cout;
using std::endl;
int a[] = { 10, 20 };
int b[] = { 30, 40 };
int main(int argc, char ** argv)
{
int * p = a;
for (int i = 0; i < 4; i++)
{
cout << *(p + i) << endl;
}
return 0;
}
它为什么工作?MVSC中阵列的存储器分配++
你不应该依赖这种行为。 – 2010-11-24 08:02:41
你是否暗示,该程序不会崩溃? – 2010-11-24 08:02:43
另请参阅:http://stackoverflow.com/questions/671703/array-index-out-of-bound-in-c和http://stackoverflow.com/questions/3658383/accessing-array-beyond-the-限制 – 2010-11-24 08:10:54