#Day4 'C' coding challenge

#Day4 'C' coding challenge

What is the output of the below code snippet? 

There are two problems with the above code snippet:

1. It is common among programmers to write half statements and move on with coding and realize only during compilation that something is missed. This is one scenario where #include has been written but to be included is not mentioned. The compiler throws an error on this scenario.

2. If #include is OK and code proceeds further, in main function, 'a' is treated as local between the braces which included between

{ int a=20; printf("%d",a); }

So, printf statement doesn't have any problem and finds the 'a' value and prints 20. There shall be a problem for the second printf

{ { int a=20; printf("%d",a); } printf(" %d",a);

For the second printf, 'a' is out of scope, it treats 'a' as undefined. So, it returns an error as "a is undefined".

The above code snippet focuses on two scenarios - common mistakes in coding, what is local and global variable.

Post a Comment

0 Comments