第6周

来源:互联网 发布:linux下软件安装 编辑:程序博客网 时间:2024/06/06 04:19
(1)
#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;  }  
(2)
#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;  } 
#include <iostream>  using namespace std;  int  a=3, b=5;  int max(int a, int b)  {      int c;      c=a>b? a:b;      return  c;  }  int main()  {      int a=8; //若无这一句,又将如何?      cout<<max(a,b)<<endl;      return 0;  } 


知识点总结:

    如果第三个程序去了那一句话会输出5,这三个程序主要是巩固了对静态局部变量、动态局部变量和全局变量,注意要区别静态和动态的局部变量

0 0
原创粉丝点击