动态申请二维数组

int main() {
int **p;
int m,n;

cout << "请输入行数和列数:" << endl;
cin >> m >> n; 

p = new int *[m];

for(int i = 0;i <= m-1;i++){
    p[i]=new int[n];
}

for(int row = 0;row <= m-1;row++){
    for(int col = 0; col <= n-1;col++){
        p[row][col] = 0;
    }
}

 

for(row = 0;row <= m-1;row++){
    for(int col = 0; col <= n-1;col++){
        cout << p[row][col] << "\t";
    }
    cout << "\n";
}

 

for(row = 0;row <= m-1;row++){
    delete [] p[row];
}
delete []p;

 

system("pause");
return 0;
}
posted on 2014-08-09 12:35  Anthony0859  阅读(133)  评论(0编辑  收藏  举报