Thread: what does static int mean?

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    14

    what does static int mean?

    what does static int mean in this situtation:

    int x =42;

    void g(int y)
    {
    static int x=7;
    x+=y;
    }

    there is another function too and the main function. thanks

  2. #2
    Registered User
    Join Date
    Aug 2002
    Location
    Hermosa Beach, CA
    Posts
    446
    It means that the function g() has an int x that is persistent between calls, and in that particular situation, it will only be initialized to 7 once (the first time g() is called), and subsequently it will have whatever value was left in it from the previous call. It's sort of a like a global variable, except it is not 'seen' except inside that particular function.
    The crows maintain that a single crow could destroy the heavens. Doubtless this is so. But it proves nothing against the heavens, for the heavens signify simply: the impossibility of crows.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  2. Game Won't Compile
    By jothesmo in forum C++ Programming
    Replies: 2
    Last Post: 04-01-2006, 04:24 PM
  3. Replies: 2
    Last Post: 03-24-2006, 08:36 PM
  4. Converted from Dev-C++ 4 to Dev-C++ 5
    By Wraithan in forum C++ Programming
    Replies: 8
    Last Post: 12-03-2005, 07:45 AM
  5. How do you search & sort an array?
    By sketchit in forum C Programming
    Replies: 30
    Last Post: 11-03-2001, 05:26 PM