-
-
Save Codeplaza/7907345 to your computer and use it in GitHub Desktop.
| #include<stdio.h> | |
| int main() | |
| { | |
| int m, n; | |
| int i = 0, j = 4; | |
| for(m = 0, n = 0; m < i, n < j; m++, n++) | |
| { | |
| printf("Codeplaza\nCodeplaza\n"); | |
| } | |
| return 0; | |
| } |
The code will print "Codeplaza" 8 times (each on a separate line). The for loop executes 4 times because n is initialized to zero and j equals to 4, and at each iteration n is incremented by one. The value of m and i doesn't matter at all, because the loop guard expression is a comma expression, that by the language rules evaluates all the operands (i.e. the expressions "m < i" and "n < j"), but results in the value of the rightmost one (thus always resulting to the value of "n < j").
Same reasoning for the second example code. The value of m is assigned to be the value of the rightmost operand of the comma expression, so it will be 15 (printf returns the number of characters written). But both the expressions will be evaluated, so the program output will be "What's up programmers ? 15"
Codeplaza
Codeplaza
Codeplaza
Codeplaza
Codeplaza
Codeplaza
Codeplaza
Codeplaza