In a technology QQ group, I tried to make a C question. I thought it was a test of the For Loop execution process.
Original question: in C language, the output result of the following code is () (select one)
Void main ()
{
Int I = 0, j = 10;
For (I = 0; I <j; I ++, j --)
{
If (j = 10)
{
Printf ("% d, % d", I, j );
J --;
}
J ++;
}
Printf ("% d, % d", I, j );
}
A) 0, 10
9,9
B) 0, 10
10, 10
C) 10, 10
D) 9,11
Many people in the group have chosen B, and the questioner has been asking for the correct results.
The correct result is:.
Haha, good basic knowledge.
Later, I wrote a code by hand, and you can understand the order of the for loop operation.
Int print1 (int I, int j)
{
Printf ("execution judgment condition, I = % d, j = % d", I, j );
Return 1;
}
Void main ()
{
Int I = 0, j = 10;
For (I = 0; (print1 (I, j) & (I <j ));
I ++, j --, printf ("execute the third statement in for (), I = % d, j = % d", I, j ))
{
If (j = 10)
{
Printf ("% d, % d", I, j );
J --;
}
J ++;
Printf ("execute the last sentence in the for loop body, I = % d, j = % d", I, j );
}
Printf ("% d, % d", I, j );
}
The running result is:
Execution condition, I = 0, j = 10
0, 10
Execute the last sentence in the for loop body, I = 0, j = 10
Execute the third statement in for (), I = 1, j = 9
Execution condition, I = 1, j = 9
Execute the last sentence in the for loop body, I = 1, j = 10
Execute the third statement in for (), I = 2, j = 9
Execution condition, I = 2, j = 9
Execute the last sentence in the for loop body, I = 2, j = 10
Execute the third statement in for (), I = 3, j = 9
Execution condition, I = 3, j = 9
Execute the last sentence in the for loop body, I = 3, j = 10
Execute the third statement in for (), I = 4, j = 9
Execution condition, I = 4, j = 9
Execute the last sentence in the for loop body, I = 4, j = 10
Execute the third statement in for (), I = 5, j = 9
Execution condition, I = 5, j = 9
Execute the last sentence in the for loop body, I = 5, j = 10
Execute the third statement in for (), I = 6, j = 9
Execution condition, I = 6, j = 9
Execute the last sentence in the for loop body, I = 6, j = 10
Execute the third statement in for (), I = 7, j = 9
Execution condition, I = 7, j = 9
Execute the last sentence in the for loop body, I = 7, j = 10
Execute the third statement in for (), I = 8, j = 9
Execution condition, I = 8, j = 9
Execute the last sentence in the for loop body, I = 8, j = 10
Execute the third statement in for (), I = 9, j = 9
Execution condition, I = 9, j = 9
9,9
--------------