码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2014-05-23 09:17:44      阅读:354      评论:0      收藏:0      [点我收藏+]

标签:class   blog   c   code   color   a   

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

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

标签:class   blog   c   code   color   a   

原文地址:http://www.cnblogs.com/zhangXH/p/3737923.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!