What is the output of the below code?
#include<stdio.h> #define FALSE 0 int main() { static int var; for(++var;++var;++var) { printf("%d ",var); } return FALSE; }
--------------------------------------------------------------
In the above program, an integer variable var with static storage type has been declared. Variable of static type is assigned a default value of 0.
In the for loop, in the initialization ++var becomes var = 0+1 = 1 which is pre-increment
When it comes to conditional check, ++var becomes, var = 1+1 = 2, which is true
When it comes to increment/decrement statement, ++var becomes, var = 3+1 = 4
So, print statement prints 4
And the loop continues till infinity as the variable is increment continuously during every conditional check.
0 Comments