1. ## Question about For (Loop)

Hi,,
I really confuse about a part of this program using for loop :

for(i=0; i<3; i++) {
for(j=0; j<3; j++)
if(matrix[i][j]==0) matrix[i][j]=no;
if(matrix[i][j]==0) matrix[i][j]=55;
++no;
}

Code:
```#include <stdio.h>

int main(){
int matrix[3][3];
int i,j, no=1;

for(i=0; i<3; i++) {
for(j=0; j<3; j++){
matrix[i][j]=0;
}
}

for(i=0; i<3; i++) {
for(j=0; j<3; j++)
if(matrix[i][j]==0) matrix[i][j]=no;
if(matrix[i][j]==0) matrix[i][j]=55;
++no;
}

for(i=0; i<3; i++) {
for(j=0; j<3; j++) {
printf("%d   ", matrix[i][j]);
if (j==2) printf("\n");
}
}

return 0;
}```
it will output 1 1 1
55 2 2
55 3 3

I really confuse about the output >_< can you please explain to me how is the process in for loop so we get that output?

I think it must be 55 1 1
55 2 2
55 3 3

I really need the explanation ASAP XD ^^
Thank you ^^

2. Sorry, you don't get off that easy!

Add some print statements into your code, and print out the array. You'll see what it's doing, and learn something about C, and basic troubleshooting, (a valuable skill to cultivate), as well.

3. You have a buffer overrun in that code. The value of a loop variable after the loop is the first value that made the condition false.
The first thing that makes j<3 false is when j is 3.
You then proceed to use j, so bad things can happen.