CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12

Threaded View

  1. #1
    Join Date
    May 2005
    Posts
    112

    Question local static variables

    hi,

    is it correct to state that a static variable is created only once and initialised only once and occupies some special global memory?

    So lets say some sub routines declare and initialise a local static variable of the same name.

    Is this possible - I mean will the variables only have local scope to the sub routines they are declared and initialised in ?
    Will they exist seperately or how are they allocated?


    Code:
    void my_func1 ()
    {
    	static int var = 0;
                    // do whatever
    }
    
    void my_func2 ()
    {
    	static int var = 0;
                    // do whatever
    }
    
    
    int main ()
    {
    	my_func1();
                    my_func2();
    	return 0;
    }
    Last edited by Moore; October 18th, 2005 at 12:52 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured