How to access 1 element in 2D dynamic array in C++

If you’re looking to create a 2D array you should take a look at this Stack Overflow post here. It has a nice image to explain how 2D memory is laid out and how to properly create the array. Remember, when you create dynamic memory using new you need to delete the memory manually with delete[]. The second response gives a code example of how to delete the 2D array. Once you have your array you can access it by cout << array[x][y], where x and y are your row and column indices. I’d focus on properly creating the 2D array and understanding that first.

Leave a Comment