C++创建二维指针问题
伊谢尔伦
伊谢尔伦 2017-04-17 13:29:16
0
1
301
int n = 0;
int **num = new int*[n];
cin >> n;

上述的代码,Line2和Line3我弄反了,为什么结果在后面进行二维数组操作的时候没有影响?

for (int i = 0; i<n; i++) {
        num[i] = new int[i+1];
        for (int j = 0; j < i+1; j++) {
            cin >> num[i][j];
        }
    }

比如我上述操作之后,我还是可以对num[][]进行读写。new的性质到底是怎样的?

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(1)
黄舟

C and C++ do not detect out-of-bounds arrays of basic types. You can play around with pointers, but doing so is dangerous

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template