navroze
navroze

Reputation: 35

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];

Upvotes: 1

Views: 668

Answers (1)

Rakholiya Jenish
Rakholiya Jenish

Reputation: 3223

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]

Upvotes: 1

Related Questions