How to change local static variable value from outside function

后端 未结 3 832
悲&欢浪女
悲&欢浪女 2021-01-26 09:00
#include 

void func() {
   static int x = 0;  // x is initialized only once across three calls of
                      //     func()
   printf(\"%d\\n\"         


        
3条回答
  •  梦毁少年i
    2021-01-26 09:19

    You can't. It's a local static variable which is invisible outside func().

    You can either use:

    1. Global static (not recommended generally).
    2. Pass it through reference/pointer parameter, or return by reference.

提交回复
热议问题