C++二维动态数组的创建与使用

版权声明:Copyright © 钟波 https://blog.csdn.net/gzu_zb/article/details/89924360
#include <iostream>
using namespace std;

int main(){
    int row,column,k=0;
    cin >> row >> column;

    int **p =  new int* [row];
    for(int i = 0; i < row; i++)
        p[i] = new int[column];

    for(int i = 0; i < row; i++)
        for(int j = 0; j < column; j++)
            p[i][j] = ++k;

    for(int i = 0; i < row; i++){
        for(int j = 0; j < column; j++)
            cout << p[i][j] << " ";
        cout << endl;
    }

    for(int i = 0; i < row; i++)
        delete []p[i];
    p = NULL;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/gzu_zb/article/details/89924360