#include <stdio.h>
void func() {
static int x = 0; // x is initialized only once across three calls of
// func()
printf("%d\n", x); // outputs the value of x
x = x + 1;
}
int main(int argc, char * const argv[]) {
func(); // prints 0
func(); // prints 1
func(); // prints 2
// Here I want to reinitialize x value to 0, how to do that ? <-- this line
return 0;
}
在上面的代码中,在调用 func() 3 次后,我想重新初始化x
为零。有什么方法可以将其重新初始化为0?