static variable

This is a discussion on static variable within the C Programming forums, part of the General Programming Boards category; Hello everyone, I am wondering how C or C++ manages static variable internally. Since each time when we again a ...

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    1,579

    static variable

    Hello everyone,


    I am wondering how C or C++ manages static variable internally. Since each time when we again a function again, if in this function, a static variable is defined, the value will be the value last time when we entered this function (i.e. will not be initialized again, and only initialized at the 1st time).

    I suspect it is stored in some global structure to reserve the value?


    thanks in advance,
    George

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,806
    Look at it basically as a global but with limited scope... only within the function where it is declared.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Registered User Tommo's Avatar
    Join Date
    Jun 2007
    Location
    Scotland
    Posts
    101
    Actually, good question. Are they stored on the heap or the stack is perhaps your question? And here is your answer.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. scope of global variable vs. static
    By chiefmonkey in forum C++ Programming
    Replies: 4
    Last Post: 06-21-2009, 01:23 PM
  2. Static variable usage
    By shwetha_siddu in forum C Programming
    Replies: 1
    Last Post: 04-02-2009, 01:33 AM
  3. static variable vs. DLL
    By pheres in forum C++ Programming
    Replies: 11
    Last Post: 02-06-2008, 02:15 AM
  4. what is static variable....?
    By gardenair in forum C Programming
    Replies: 4
    Last Post: 04-09-2003, 09:54 AM
  5. Replies: 3
    Last Post: 10-10-2002, 08:34 AM

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