multi-demensional array confusion
multi-demensional arrays are getting me kinda confused. I have a question. Firstly, have a look at this loop:
Code:
int board[7][7] = {0};
for(int n = 0;n < 8;n++) {
for(int i = 0;i < 8;i++) {
cout << "[" << board[n][i] << "]";
}
cout << endl;
}
all i want it to do is project the correct matrix, which should be a big box full of zeros, because i'm doing nothing more to it yet. However, the very last number on the 7th line, and all of the 8th line are overloads, and bring random digits from surrounding memory. any hints why?
the weird thing is, if i add a line of code before the loop like:
when the program runs, i'll still get overflows on the last line, except for 7,6! I've done all kinds of debugging, and it looks like the loop is producing the correct numbers, none over 7, but it just goes crazy on the last line when i have it display the matrix! I know i could patch this problem up by adding unnessecary lines of code, but i'm sure there's a more reasonable explination.
also, is there a way to make changes to a whole row at once, like if you want row 4 to entirely have the same number, can you do it with a command, and not with a loop?
thanks.