Exforsys

Online Training

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 ...


Go Back   Exforsys > Programming Talk > C and C++

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-15-2007, 07:36 PM
Senior Member
 
Join Date: Apr 2006
Posts: 144
caradoc is on a distinguished road
Exclamation 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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 05-16-2007, 04:40 PM
Senior Member
 
Join Date: Apr 2006
Posts: 162
sammy is on a distinguished road
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads

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


All times are GMT -4. The time now is 10:57 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Copyright 2004 - 2007 Exforsys Inc. All rights reserved.