第十二周 项目一阅读程序(2)

来源:互联网 发布:php换行符 编辑:程序博客网 时间:2024/04/28 07:42

  阅读下面有全局变量的程序,掌握全变量的存储特征,必要时单步调试。

代码1:

#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;}


运行结果:

预计运行结果:8

实际运行结果:8

知识点总结:全局变量在程序中不再特殊赋值的话,一直用该数,若有特殊赋值,按新赋值的计算,如此程序。

***去掉"int a=8"的代码及运行结果:

#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(){     cout<<max(a,b)<<endl;    return 0;}

学习心得:不怕慢,就怕懒!一点点积累!!

0 0
原创粉丝点击