Created
December 11, 2013 09:17
-
-
Save Codeplaza/7907345 to your computer and use it in GitHub Desktop.
Quiz 3.0 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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"