static 修饰变量 用 static 修饰的变量只会在第一次运行的时候做一次初始化,后续即使多次调用也不会再重新初始化。 123456789101112131415161718192021void func(int value) { static int counter = value; std::cout << "func(" << value << ").counter = " << counter << "\n"; counter++;}int main() { func(5); func(7); func(6); func(10); func(20);}/*func(5).counter = 5func(7).counter = 6func(6).counter = 7func(10).counter = 8func(20).counter = 9*/ static 修饰函数