第十二周项目一:程序阅读(二)静态局部变量

来源:互联网 发布:linux安装telnet命令 编辑:程序博客网 时间:2024/04/30 21:26
/**copyright (c) 2014, 烟台大学计算机学院.*All rights reserved.*文件名称:test.cpp *作者:陆云杰*完成日期:2014年11月14日 *版本号:v1.0* **/#include <iostream>using namespace std;int f(int n);int main(){    cout<<f(5)<<"  ";    cout<<f(8)<<endl;    return 0;}int f(int n){    static int a=2;    int b=0;    a+=n;    b+=a;    return b;}    


 

预计输出:7 15

 

实际输出:

 

 

学习心得:理解了静态变量的计算存储方式。

0 0