Static variables in functions

This is a discussion on Static variables in functions within the C Programming forums, part of the General Programming Boards category; As a sort of lame approach to explaining static variables in functions to noobs (like myself), could you say that, ...

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    32

    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:

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

    Code:
    int x = 5;
    
    void func(void)
    {
        x++;
    }
    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
    Posts
    14,826
    Other than variable scope, it has the same effect.


    Quzah.
    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, 06:24 PM
  4. Order of initialization of static variables
    By Sang-drax in forum C++ Programming
    Replies: 4
    Last Post: 06-20-2004, 05:31 PM
  5. Static functions
    By Morgan in forum C Programming
    Replies: 2
    Last Post: 01-20-2003, 05:00 AM

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