Day#24 'C' Coding Challenge

Day#24 'C' Coding Challenge

What is the output of the below code?

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

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

The above code tests below scenarios.

1. What is the default value of an uninitialized variable?

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

The value of var1 is indeterminate. This is a common error seen in embedded programming where programmers miss to initialize the variables and are used which lead to errors down the program. If you are compiling with a generic C IDE you might see that var1 printed as Zero but this may not be the case with different compilers which report uninitiated variables. To put it other way, when a variable is not initialized, it takes the value present in the memory location it is assigned to which could be a garbage value.

Post a Comment

0 Comments