Can I access static variables inside a function from outside

后端 未结 8 1399
夕颜
夕颜 2021-01-02 04:15

C/C++: Can I access static variables inside a function from outside? For example:

#include 
using namespace std;

void f()
{
    static int c         


        
8条回答
  •  我在风中等你
    2021-01-02 04:29

    No, static variable has its scope limited to block in which it is defined, while its life time is though out the process, so as variable is defined in function it will get into existence once this method is called but in order access it we need to be in function scope.

提交回复
热议问题