Filling a 2D Array.

I am a beginner programmer trying to understand C++ better. I am stuck with a problem, I do not understand how to load a 2D array. I have written some code, but when I go over it in my head it makes no sense.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <iomanip>

using namespace std;

const int EIGHT = 8;
const int EMPTY = ".";

int main()
{
    int gameboard [EIGHT][EIGHT];
    
    for (int row = 0; row < EIGHT; row++)
    {
        for (int col=0; col < EIGHT; col++)
        {
            gameboard[row][col] = EMPTY;
            }
            }
            cout << gameboard << endl;

return 0;
}


I have read numerous articles about 2d arrays, I just do not understand them.

Thanks in advance.

I have to ask... why are you defining a constant variable named EIGHT with the value of 8, when you could just type 8 as the size for the array?
in my assignment he wanted us to define a constant that was the size of the array. Which it had to be a grid of 8x8.
2D arrays are nothing just set 1D arrays. Consider them in Matrix form. In you program it is 8*8 array. Compare the same with 8*8 matrix. Then try to understand the memory allocation for each element.
Alright, I figured it all out. Thanks for the help
Topic archived. No new replies allowed.