简体   繁体   中英

How to take input to 2d Dynamic Array in c++

I have created a 2d array using pointers.How do I take input to this 2d array?

int **p = new int*[r];
for(int i = 0; i < r; i++)
    p[i] = new int[c];

To access any element of 2-D array, imagine it as an array of array. So to access jth element in ith row, it would be like selecting jth element from p[i] array. So it would be p[i][j] .

Hence, to access any jth column (element) in ith row, simply use:

p[i][j]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM