Question: I'm new to C++ but have had experience before with languages like java and I am starting off by making a simple command line Xs and Os game. When it came to creating the grid I found that I could initiate it in two different ways:

```
int grid[3][3] = {{0, 0, 0 },
                  {0, 0, 0 },
                  {0, 0, 0 }};

```

and:

```
int grid[3][3];
for (int x = 0; x < 3; ++x)
{
    for (int y = 0; y < 3; ++y)
    {
        grid[x][y] = 0;
    }
}

```

Is one method better than the other in any way and should I get into a habit of using one rather than the other?

Thanks

Answer: 
In c++ you can write 

```
int grid[3][3] = {};

```

This is enough see eg [how does array[100] = {0} set the entire array to 0?](https://stackoverflow.com/questions/629017/how-does-array100-0-set-the-entire-array-to-0) and <http://www.cplusplus.com/doc/tutorial/arrays/>
I like to use [memset](http://www.cplusplus.com/reference/cstring/memset/). It makes the code much nicer. Both the ways you suggested are valid but are more of a `C` dialect. A more object oriented approach could be using a `matrix` class with a constructor. Of course, in a real world you would probably use something like [Boost](http://www.boost.org/doc/libs/1_42_0/libs/numeric/ublas/doc/matrix.htm) for a general solution..