I am trying to create a 3*N array where N is specified at runtime.
int *array[3];
int breadth;
cin>>breadth;
for(int i=0;i<3;i++)
array[i] = new int[breadth];
array[0][breadth-1] = 1;
array[1][breadth-1] = 2;
array[2][breadth-1] = 3;
array[3][breadth-1] = 69; // how does this work
cout<<array[3][breadth-1]<<endl;
The output is 69 and I am surprised that the indicated line works even though the maximum size (3) has been exceeded. Does anyone know why that element is accessible?
I tried other sizes like 4N and 5N, with the same results
精彩评论