第12周 项目1-阅读程序(2)
来源:互联网 发布:windows平板推荐 2016 编辑:程序博客网 时间:2024/05/01 09:09
/* * Copyright (c) 2014, 烟台大学计算机学院 * All rights reserved. * 文件名称:test.cpp * 作 者:呼亚萍 * 完成日期:2014年 11 月 13 日 * 版 本 号:v1.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;}
运算结果:
#include <iostream>using namespace std;void cude();int main(){ extern int x; x=5; cude(); cout<<x<<endl; return 0;}int x=10;void cude(){ x=x*x*x;}
运算结果:
知识点总结:
在第一个程序中,无int a=8这一句,结果输出3,默认值为a=3,b=5. 在第2个程序中,extern用于提示编译器通过此变量和函数时,在其他模块中寻找其定义,若无extern,默认 int x=10,结果输出5;若无x=5,默认x=10,结果输出1000.加深了对全局变量的了解。
学习心得:
在学习过程中,利用身边的资源进行学习,例如云学堂,百度等,借助外力了解了有关extern的作用,加油!
0 0
- 第12周项目1-阅读程序(2)
- 第12周 项目1-阅读程序(2)
- 第12周项目1--阅读程序(2 全局变量)
- 第12周项目 程序阅读(2)
- 第12周项目 程序阅读(1)
- 第12周项目1-阅读程序(1)
- 第12周项目一 程序阅读题(2)
- 第12周项目-程序阅读(2)
- 第12周项目一 程序阅读题(1)
- 第12周项目1-阅读程序(3)
- 第12周 项目1-阅读程序(3)
- 第12周项目1 阅读程序(整型变量)
- 第12周项目1-阅读程序(4)
- 第12周项目1-程序阅读(5)
- 第12周 项目1-阅读程序(5)
- 第12周项目1 --默认参数(阅读程序)
- 第12周 项目1-阅读程序(4)
- 第12周项目-程序阅读(1)
- c++builder:Project Project1.exe raised exception class EAccessViolation with message 'Access violati
- Python sort sorted 详解
- Search for a Range
- selenium封装WebDriver
- 访问控制列表ACL
- 第12周 项目1-阅读程序(2)
- gzip和tar常见用法
- 第十二周 项目一--阅读程序(1)
- 数据结构与算法分析笔记(2)--线性表
- Android之广播(Broadcast)
- 数据库基础--MySQL中的约束
- taobao
- android图形系统之Paint(画笔)类详解
- c#开发Mongo笔记第九篇