
- Forum
- Programming Talk
- C and C++
- Why initialization Essential
Why initialization Essential
This is a discussion on Why initialization Essential within the C and C++ forums, part of the Programming Talk category; I had a quick small doubt when I was doing my programming with C. Is it essential that all global ...
-
Why initialization Essential
I had a quick small doubt when I was doing my programming with C. Is it essential that all global variables in C must be initialized to zero? What is the reason behind this initialization? Say if I code a program as below:
#include <stdio.h>
main()
{
int i;
printf("%d",i);
}
Here I have not initialized the global variable i. In this case will the output be junk value. Why is it so can someone kindly explain me what happens inside the system in this context.
-
It is a must that you must initialize the global variables in C programming language. Now coming to your next question of whether it is to be initialized with zero. The reason is simple. If you are not initializing with zero the memory would have some junk value which would be used in the program when the memory area is accessed. So make it a practice to always initialize global variables in C programming language with zero.

Reply With Quote





