代码如下:
#include <iostream>
int Gather();
int main() {
int gwool = 0;
while (gwool < 60) {
gwool = Gather();
std::cout << gwool << std::endl;
}
}
int Gather() {
// A static local variable.
static int wool = 55;
return ++wool;
}
输出:
56
57
58
59
60
如果没有static关键字,程序将陷入死循环。