Search code examples
c++static-methodsstatic-variables

Where does the local static variable inside static member function resides in memory?


Where does the local static variable inside static member function resides in memory? For example :

class Foo
{
public:
    static void Bar()
    {
         static int fooBar;
    }
};

Where does 'fooBar' resides in memory and when it was allocated.


Solution

  • That is obviously compiler and platform specific but generally, on PC, it resides in same memory as global variables. It gets initialized on first entry to the function.