What is the output of the below code?
#include<stdio.h> int var = 5; void main() { do printf("value = %d ", var ); while(var++<=5); }
--------------------------------------------------------
in the above program do-while loop is used. In the do-while loop, first the instructions in the do statement are executed, so, the printf is executed and prints value = 5. The while statement has the condition which is checking var++ <=5, as var++ is post increment, var++ increment happens after the conditional check, the condition is TRUE for the first time as (5 <= 5). Then again the statement in the do is executed and value = 6 is printed. The next conditional check fails (6<=5) and loop is exited.
0 Comments