Can I access static variables inside a function from outside

后端 未结 8 1376
夕颜
夕颜 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:51

    A static variable has a scope within the block but it has a lifetime of throughout the program so you cant access the coun tvariable try returning a pointer from the function.

提交回复
热议问题