Thread: Static variables in functions

  1. #1
    Registered User
    Join Date
    Dec 2005

    Static variables in functions

    As a sort of lame approach to explaining static variables in functions to noobs (like myself), could you say that, FOR THE FUNCTION IN QUESTION, the following:

    void func(void)
        static int x = 5;
    is roughly the same as:

    int x = 5;
    void func(void)
    Don't kill me if this is so wrong, I've just started fiddling around with static.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Other than variable scope, it has the same effect.

    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. question about static members and functions
    By e66n06 in forum C++ Programming
    Replies: 5
    Last Post: 01-07-2008, 02:41 PM
  2. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 05:42 PM
  3. Linking errors with static var
    By Elysia in forum C++ Programming
    Replies: 8
    Last Post: 10-27-2007, 05:24 PM
  4. Order of initialization of static variables
    By Sang-drax in forum C++ Programming
    Replies: 4
    Last Post: 06-20-2004, 04:31 PM
  5. Static functions
    By Morgan in forum C Programming
    Replies: 2
    Last Post: 01-20-2003, 05:00 AM