global variables.

This is a discussion on global variables. within the C Programming forums, part of the General Programming Boards category; does always global variables are initialised to 0? if not how to initialise an array to zero value in the ...

  1. #1
    Registered User
    Join Date
    Aug 2008
    Posts
    46

    global variables.

    does always global variables are initialised to 0?
    if not how to initialise an array to zero value in the global..

  2. #2
    Registered User
    Join Date
    Aug 2008
    Posts
    15
    Yes, global variables are initialized to zero (even static variabels).

  3. #3
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    Quote Originally Posted by vapanchamukhi View Post
    does always global variables are initialised to 0?
    if not how to initialise an array to zero value in the global..
    Yes, global variables (and *only* global variables) are guaranteed to be initialized to 0. But global variables are evil... Do without them if you can

    QuantumPete
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Pedantics:
    As patil states, global variables and static variables (they are global in all aspects except for where they are visible) are initialized to zero if they are not otherwise initialized.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Aug 2008
    Posts
    46
    then what is the difference between bss and initialised segments?

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by vapanchamukhi View Post
    then what is the difference between bss and initialised segments?
    What do you think it is? Does the term "intialised" mean something to you?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 08-06-2008, 09:59 AM
  2. scope of global variables
    By laertius in forum C++ Programming
    Replies: 4
    Last Post: 10-15-2006, 01:59 AM
  3. global variables - okay sometimes...?
    By MadHatter in forum C++ Programming
    Replies: 21
    Last Post: 01-21-2003, 03:23 PM
  4. global variables
    By rdnjr in forum Linux Programming
    Replies: 0
    Last Post: 01-07-2003, 09:28 AM
  5. Global variables? Bad! Yes, but to what extent?
    By Boksha in forum C++ Programming
    Replies: 6
    Last Post: 05-26-2002, 04:37 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21