As per for loop syntax, sequesnce in which all four component executes are as follow:
First iteration: Initialization : printft("%d ",++i) print 1 Condition : printft("%d ",i++) print 1 and then i becomes 2. printf function return 1 which is evaluated true by compiler. Body of loop: printft("%d ",i++) print 2 and i becomes 3. If condition becomes false. So, next Increament : printft("%d ",++i) print 4 and value of i is 4.
Second iteration: Condition : printft("%d ",i++) print 4 and then i becomes 5. printf function return 1 which is evaluated true by compiler. Body of loop: printft("%d ",i++) print 5 and i becomes 6. If condition becomes false. So, next Increament : printft("%d ",++i) print 7 and value of i is 7.
Third iteration: Condition : printft("%d ",i++) print 7 and then i becomes 8. printf function return 1 which is evaluated true by compiler. Body of loop: printft("%d ",i++) print 8 and i becomes 9. If condition becomes true. So, due to break statement, control goes out of for loop.
Concept: sizeof() operator only evaluate the memory size required based on data type of the input parameter paased but not execute it. Therefore, in the above program, sizeof(++i) only evaluate the resultant data type of ++i. It will not executes the statement ++i. Therefore, value of i never change and due to that program print "practicepaper" infinite times.
Consider the while loop condition: a + 1 ? --a : ++b
In first iteration:
a + 1 = 3 (True)
So ternary operator will return --a i.e. 1
In C program 1 means true. So, while condition is true. Hence printf statement will print 1
In second iteration:
a+ 1 = 2 (True)
So ternary operator will return --a i.e. 0
In C program zero means false so while condition is false. Hence, program control will come out of the while loop.
First iteration:
i = 0
i < n i.e. 0 < 6 i.e. if loop condition is true.
Hence printf statement will print: Mock
Due to continue keyword program control will come at the beginning of the for loop and value of variable i will be:
i += 3
i = i + 3 = 3
Second iteration:
i = 3
i < n i.e. 3 < 6 i.e. if loop condition is true.
Hence printf statement will print: Mock
Due to continue keyword program control will come at the beginning of the for loop and value of variable i will be:
i += 3
i = i + 3 = 6
Third iteration:
i = 6
i < n i.e. 6 < 6 i.e. if loop condition is false.
Hence program control will come out of the for loop.
break keyword breaks only current loop only. So inner for loop with variable j will executes only one time and the due to break statement it will transfer control out of that loop. Keep in mod that it will not affect to the outer loop with variable i. Therefore, total 5 times practicepaper will be printed.