第12周项目1-阅读程序(1)

来源:互联网 发布:php中= 编辑:程序博客网 时间:2024/04/27 05:12
/*  2. * Copyright (c) 2014, 烟台大学计算机学院  * All rights reserved.  * 文件名称:test.cpp  5 作    者:刘畅  * 完成日期:2014 年 11  月  13  日  * 版 本 号:v1.0  8. *  9. * 问题描述:阅读以下两个有静态局部变量的程序;  * 输入描述: 啥也不用输;  * 程序输出: ;  */    


#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;}/*预计运行结果为:<u>7    15</u>  实际运行结果为:<u>7    15</u>


 

#include <iostream>using namespace std;int func (int a,int b){static int m=0,i=2;i+=m+1;m=i+a+b;return m;}int main( ){int k=4,m=1,p;p=func(k,m);cout<<p<<endl;p=func(k,m);cout<<p<<endl;return 0;}/*预计运行结果为:<u>8    17</u>  实际运行结果为:<u>8    17</u>


 

知识点总结:

理解了静态局部变量的作用。

0 0
原创粉丝点击