1. ## beginning array question

I have array[2][2] and I want to initialize this with all 9 segments having a value of 0. Is there a way to set the entire array to 0, without manually entering a line of code which says

array[0][3]=0;

for every segment?

2. Loop trough the array, and set the value to 0:
Code:
```int myArr[3][3];
int i, j;

for (i=0; i<3; i++)
for (j=0; j<3; j++)
myArr[i][j] = 0;```

3. int array[2][2] = {0};
--edit--
This is what you put when declareing the array. all elements will be set to 0.

4. Thanks, I love this board.

5. Is the below proper syntax:

Code:
```if (maploc[x][y]==[0][0])
{
cout<<"hi";
}```
also, when i do:

int maploc3x3[3][3]={0};

i get a warning about my initialization not being properly bracketed

6. >maploc[x][y]==[0][0]
A no no maploc[x][y] is one element, so you just need:
Code:
`if (maploc[x][y] == 0)`
Also try the way I wrote here to initialise the array, you even can make a function to initialise arrays.

7. Well what if I want to do something only when for maploc[x][y] x=3 and y=2? Im trying to make a map btw, but now im trying to figure out some way I could use an array and maybe a loop to simplify things

8. >Well what if I want to do something only when for maploc[x][y] x=3 and y=2?

Ok, let's suppose we have an 2D array. We want to loop trough all the elements of this array, if it is 1, we print the message "one" if it is 2, we print the message "two" and same with 3.

Code:
```int myArr[3][3]; //I suppose you fill the array alone...
int x,y;
....
....
for (x=0; x<3; x++)
for (y=0; y<3; y++) {
if (myArr[x][y] == 1)
puts("One");
else if (myArr[x][y] == 2)
puts("Two");
else if (myArr[x][y] == 3)
puts("Three");
}```
Of course here you could use a 'switch' to make the code more readable.

9. Im not understanding something, what if the array doesnt equal {2} but it equals [1][3] ?

10. You're not understanding the point of 2D arrays. Look, I'm passing over ALL elements of this array.

[0][0] is one element
[0][1] is another
[0][2] is another
[1][0] is another

I check wether in [0][0] it contains the value 1, 2 or 3.
I check wether in [0][1] it contains the value 1, 2 or 3.
I check wether in [0][2] it contains the value 1, 2 or 3.
I check wether in [1][0] it contains the value 1, 2 or 3.

11. Is there no way to check that it has [0][1] and not [1][0] ?

12. yes and I did check it
Lets say you just want to check [0][0], [0][1] and [0][2]. Put in your mind, they are ONE element, even if to acess them you write 2 numbers, they're one element and can hold ONLY one integer.

Code:
```for (i=0; i <= 0 ; i++)
for (j=0; j<3; j++) {
if (myArr[i][j] == 1)
//do something
else if (myArr[i][j] == 2)
//do something
......
}```

13. So [1][1] is the same thing as [1][0] ?

14. No, I told you... [1][1] is one element, [0][1] is another. Draw this in your mind as an matrix:
Code:
```[0][0]      [0][1]      [0][2]
[1][0]      [1][1]      [1][2]
[2][0]      [2][1]      [2][2]```
Now check by yourself if [0][1] is the same as [1][1]

15. what Im trying to do is create a map

00 01 02
10 11 12
20 21 22

and when

you are at 00 it does one thing, like

cout<<"You are at 0 0."

and when at 22 it does another thing, like

cout<<"You are at 2 2."

Do you see what Im confused about?