Day#22 'C' Coding Challenge

Day#22 'C' Coding Challenge

What is the output of the below program?

#include <stdio.h> int var1 = 5; void main() { function: printf("%d\n",var1); ++var1; if(var1<5) goto function; }

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

The above code tests two scenarios:

1. global variables
2. usage of goto statement

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

function is encountered once main is entered and execution continues
var1 is printed and is 5
var1 is incremented and but now the value is still 5 as var1 is just incremented but not assigned,
 now if condition fails as 5<5 is false and execution is completed.

goto is an unconditional jump statement in C language

Post a Comment

0 Comments