1

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

1 Answer 1

1

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]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.