在函数内部声明的变量为局部变量,该变量只存活于该函数中
#include<iostream> void show(int); int main(){ int x = 1; show(x); std::cout << x << std::endl; return 0; } void show(int x){ x = x + 1; std::cout << x << std::endl; }
输出结果:
2
1