【C++基础】关键字static 局部变量

时间:2014-05-23 09:17:44   收藏:0   阅读:354

1.局部变量

static局部变量和普通局部变量有什么区别:static局部变量只被初始化一次,下一次依据上一次结果值;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int test(int j){
static int i=10;
i=i+j;
return i;
}
 
int main(void)
{
    ////美图秀秀笔试
     
    int m=test(12);
    int n=test(4);
    cout << m <<endl; //输出 22
    cout << n <<endl; //输出 26
}

  

【C++基础】关键字static 局部变量,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!