2.5 局部变量

在函数内部声明的变量为局部变量,该变量只存活于该函数中

#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

posted @ 2015-05-14 13:54  cppstudy  阅读(126)  评论(0编辑  收藏  举报