Day#44 'C' Coding Challenge

Day#44 'C' Coding Challenge

What is the output of the below code?

#include<stdio.h> int var; void main() { for(var=10, var=200; var<=200, var<=10; var++) printf("%d", var); }

----------------------------------------------------------

The above code tests below scenarios:

1. for loop 
2. multiple declarations and multiple condition checks within a for loop

----------------------------------------------------------

In a general usage, for loop has single initiation, single condition check, single increment/decrement operation. In the code snippet above, there are two initiations and two condition checks. In such scenario, compiler considers the second statement as the valid check. So, indirectly the for loop is,

for(var=200;var<=10; var++)

The above for loop meant the condition check fails and loop is exited. So, there shall be no output from this code.

Post a Comment

0 Comments