#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 に再初期化する方法はありますか?