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 ...
|
|||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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.
|
![]() |
| Thread Tools | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| ORACLE initialization or shutdown in progress | Christopher_BG | Oracle Database | 1 | 12-29-2006 01:59 PM |
| Initialization Parameter | sammy | Oracle Database | 2 | 12-28-2006 03:44 PM |
| EFS-310-051: Not A Valid EFSTest Initialization File ... | brian.pedersen | Certification News | 1 | 06-15-2005 04:50 AM |
| Few essential tips for Immigration | sanereddy | Immigration Help | 0 | 10-24-2004 04:56 PM |
| Solving Lazy Initialization and double checked locking problem | Vinay Aggarwal | Software Patterns | 19 | 02-18-2004 05:34 PM |