I am not understanding what the output to this for loop is p=2 and q=3.
Here is my reasoning, if a kind person can point to where I am wrong.
Code:
main(){
int p, q;
for (p = q = 0; p < 3; p++)
{
q += p;
printf("%d", q);
system("pause");
}
}
Trace:
p=0 --> initial value
q=0 --> initial value
0<3 is TRUE --> evaluation
OUTPUT: q=0 -->execution
p=0 --> update
0<3 is TRUE --> evaluation
p=1 --> post increment update
OUTPUT: q=1 --> execution
p=1 -->update
1<3 is TRUE -->evaluation
p=2 -->post increment update
OUTPUT: q=3 --> execution
p=2 --> update
2<3 is TRUE --> evaluation
p=3 --> post increment update
OUTPUT: q=6 -->execution
p=3 -->update
3<3 is False -->evaluation
Terminate program