PROGRAMMING METHDOLODGY AND SOFTWARE ENGINEERING(PPT讲稿)C Programming Review

EE31331 PROGRAMMING METHODOLOGY AND SOFTWARE ENGINEERING PROGRAMMINGMETHDOLODGY AND SOFTWAREENGINEERING 港城市大 Copyrighto1998 Angus Wu
PROGRAMMING METHDOLODGY AND SOFTWARE ENGINEERING Copyright©1998 Angus Wu EE 31331 PROGRAMMING METHODOLOGY AND SOFTWARE ENGINEERING

C Programming review PROGRAMMINGMETHDOLODGY AND SOFTWAREENGINEERING 港城市大 Copyrighto1998 Angus Wu
PROGRAMMING METHDOLODGY AND SOFTWARE ENGINEERING Copyright©1998 Angus Wu C Programming Review

Program Structure local and global variable Storage classes Pointers fUnction Call PROGRAMMINGMETHDOLODGY AND SOFTWAREENGINEERING 港城市大 Copyrighto1998 Angus Wu
PROGRAMMING METHDOLODGY AND SOFTWARE ENGINEERING Copyright©1998 Angus Wu Program Structure •Local and Global Variable •Storage Classes •Pointers •Function Call

Local variable variables declared within a function body include int main o int next, n; / next input, number of inputs * long 0; / running total * double avgi /* average of input values * for (n=0; scanf("i",&next)== 1;n++) sum += nexti avg =(n== 0)? 0.0:(double)sum/n; printf("Average of %i values is f.\n",n, avg)i return 0; next, sum, avg are local variables of main PROGRAM MINGMETHDOLODGY AND SOFTWAREENGINEERING 港城市大 Copyrighto1998 Angus Wu ol Hone Kone
PROGRAMMING METHDOLODGY AND SOFTWARE ENGINEERING Copyright©1998 Angus Wu Local Variable • variables declared within a function body #include int main() { int next, n; /* next input, number of inputs */ long sum = 0; /* running total */ double avg; /* average of input values */ for (n = 0; scanf("%i", &next) == 1; n++) sum += next; avg = (n == 0) ? 0.0 : (double) sum / n; printf("Average of %i values is %f.\n", n, avg); return 0; } next, sum, avg are local variables of main

Local variable initializing local variables don'tcount on local variables automatically being initialized to zero long sum =0;/* running total * PROGRAMMINGMETHDOLODGY AND SOFTWAREENGINEERING 港城市大 Copyrighto1998 Angus Wu
PROGRAMMING METHDOLODGY AND SOFTWARE ENGINEERING Copyright©1998 Angus Wu Local Variable • initializing local variables • don’t count on local variables automatically being initialized to zero long sum = 0; /* running total */

Local variable variables declared within a block include int main o int next, n;/* next input, number of inputs * long SUnn i/* running total * for (n =0; scanf(gi,&next)== 1; n++)i sum+=nex七 /* compute and print input average * double avg =(n == 0)? 0.0: (double)sum /n; 2 printf("Average of i values is f.\n", n, avg)i return 0; avg is declared when it is needed PROGRAMMINGMETHDOLODGY AND SOFTWAREENGINEERING 港城市大 Copyrighto1998 Angus Wu ol Hone Kone
PROGRAMMING METHDOLODGY AND SOFTWARE ENGINEERING Copyright©1998 Angus Wu Local Variable • variables declared within a block avg is declared when it is needed. #include int main() { int next, n; /* next input, number of inputs */ long sum = 0; /* running total */ for (n = 0; scanf("%i", &next) == 1; n++){ sum += next; { /* compute and print input average */ double avg = (n == 0) ? 0.0 : (double) sum / n; printf("Average of %i values is %f.\n", n, avg); } return 0; }

Local variable block/compound statements group of statements surrounded by braces statement statement Or statement statement PROGRAM MINGMETHDOLODGY AND SOFTWAREENGINEERING 港城市大 Copyrighto1998 Angus Wu ol Hone Kone
PROGRAMMING METHDOLODGY AND SOFTWARE ENGINEERING Copyright©1998 Angus Wu Local Variable • block/compound statements group of statements surrounded by braces { statement; . . statement; } or statement, statement;

Scope of variable int maino int sq(int x) intx: XXX, return x: X=25 x=sq x) printf((%dln”,x); return o 港城市大 PROGRAMMING METHDOLOGY AND SOFTWAREENGINEERING Copyrighto1998 Angus Wu ol Hone Kone
PROGRAMMING METHDOLOGY AND SOFTWARE ENGINEERING Copyright©1998 Angus Wu int main() { int x; x= 25; x= sq (x); printf(“%d\n”, x); return 0; } int sq ( int x) { x=x*x; return x; } Scope of Variable

Scope of variable include int sa (int x)i int main fint xi 25 printf(" The address of x in main is d\n",&x)i x= sq(x)i printf("gd\n", x) return 0 int sq(int a) printf(" The address of a in sq is d \n", &a) printf(" what is x d\n", x)i a=aai return ai 港城市大 PROGRAMMING METHDOLOGY AND SOFTWAREENGINEERING Copyrighto1998 Angus Wu ol Hone Kone
PROGRAMMING METHDOLOGY AND SOFTWARE ENGINEERING Copyright©1998 Angus Wu Scope of Variable #include int sq(int x); int main() {int x; x= 25; printf(" The address of x in main is %d\n", &x); x= sq(x); printf("%d\n", x); return 0; } int sq(int a) { printf(" The address of a in sq is %d\n", &a); printf(" what is x %d\n", x); a=a*a; return a; }

Local variable Lifetime they exist only from block entry to block exit they exist/are accessible only within the function where they are declared when enter a block/function, space is reserved for its local variables when exit the block/function the reserved space Is free PROGRAMMINGMETHDOLODGY AND SOFTWAREENGINEERING 港城市大 Copyrighto1998 Angus Wu
PROGRAMMING METHDOLODGY AND SOFTWARE ENGINEERING Copyright©1998 Angus Wu Local Variable Lifetime • they exist only from block entry to block exit • they exist/are accessible only within the function where they are declared • when enter a block/function, space is reserved for its local variables • when exit the block/function, the reserved space is free
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 《神经网络 Neural Networks》课程教学资源(PPT课件讲稿)Ch 8 Artificial Neural networks.pptx
- 电子工业出版社:《计算机网络》课程教学资源(第五版,PPT课件讲稿)第五章 运输层.ppt
- 《Web编程实用技术教程》课程教学资源(PPT课件讲稿)第5章 MFC WinSock类的编程.ppt
- 《数字图像处理》课程PPT教学课件(讲稿)第二章 图像获取、显示和表示.ppt
- 香港中文大学:《Topics in Theoretical Computer Science》课程教学资源(PPT课件讲稿)量子计算 Quantum computing.pptx
- 香港科技大学:深度学习导论(PPT讲稿)Introduction to Deep Learning.pptx
- 北京大学软件研究所:高级软件工程(PPT讲稿)云计算与平台即服务.ppt
- 合肥学院:《数据库原理与应用》课程教学资源(PPT课件)第1章 数据库系统概述(主讲:叶潮流).ppt
- 《数据库原理与应用》课程PPT教学课件(SQL Server)第9章 存储过程和触发器.ppt
- 《The C++ Programming Language》课程教学资源(PPT课件讲稿)Lecture 02 Procedure-Based Programming.ppt
- 东南大学:《数据结构》课程教学资源(PPT课件讲稿)第七章 图.ppt
- 北京大学:《高级软件工程》课程教学资源(PPT课件讲稿)第一讲 软件与软件开发.ppt
- 西安电子科技大学:《现代密码学》课程教学资源(PPT课件讲稿)第二章 流密码(主讲:董庆宽).pptx
- 《Photoshop基础教程与上机指导》教学资源(PPT讲稿)第18章 扫描和修饰图像.ppt
- 中国水利水电出版社:《单片机原理及应用》课程PPT教学课件(C语言版)第8章 单片机系统扩展(主编:周国运).ppt
- 西安电子科技大学:《操作系统 Operating Systems》课程教学资源(PPT课件讲稿)Chapter 04 Memory Management.ppt
- 《网页设计》课程教学资源:课程教学大纲.doc
- 《人工智能技术导论》课程教学资源(PPT课件讲稿)第3章 图搜索与问题求解.ppt
- 清华大学:TCP and Congestion Control(1).pptx
- 清华大学:域内路由选择(PPT课件讲稿)Intra-domain routing.pptx
- 计算机网络技术基础(PPT课件讲稿).ppt
- 《网络搜索和挖掘关键技术 Web Search and Mining》课程教学资源(PPT讲稿)Lecture 13 Matrix Factorization and Latent Semantic Indexing.ppt
- 多媒体技术及应用(PPT讲稿)多媒体音频技术.ppt
- 山东大学:《微机原理及单片机接口技术》课程教学资源(PPT课件讲稿)第四章 指令系统及汇编语言程序设计(4.1-4.4).ppt
- 东南大学:《C++语言程序设计》课程教学资源(PPT课件讲稿)Chapter 13 Object-Oriented Programming - Polymorphism.ppt
- 《C++语言程序设计》课程教学资源(PPT课件)第14讲 运算符重载.ppt
- 淮阴工学院:《数据库原理》课程教学资源(PPT课件讲稿)第4章 结构化查询语言SQL.ppt
- 《计算机网络 COMPUTER NETWORKS》课程教学资源(PPT课件讲稿)Chapter 18 互联网协议 Internet Protocols(IP).ppt
- 计算机应用专业《计算机网络》教学大纲.doc
- 《计算机网络安全》课程教学资源(PPT课件讲稿)第四章 数据加密技术.ppt
- 西安培华学院:《计算机网络工程》课程教学资源(PPT课件讲稿)第1章 网络工程知识(主讲:张伟).ppt
- 对外经济贸易大学:《大学计算机基础》课程电子教案(PPT课件)第5章 PowerPoint幻灯片制作(PowerPoint 2010).pptx
- 中国地质大学(武汉):R语言入门教程(PPT讲稿).ppt
- 西南民族大学:软件需求分析与总体设计(PPT讲稿,主讲:殷锋).ppt
- 《软件测试 Software Testing》教学资源(PPT讲稿)Part 1 The Big Picture.ppt
- 系统编程工具REXX和CLIST.ppt
- 北京大学:基于信息利用的烟花算法研究(PPT讲稿)Research on Fireworks Algorithms from the Perspective of Information Utilization.pptx
- 《ARM嵌入式软件开发》课程教学资源(PPT课件讲稿)第三章 ARM体系结构及编程模型.ppt
- 《大型机系统管理技术》课程教学资源(PPT课件讲稿)第2章 大型服务器外存管理.ppt
- 《计算机组成原理》课程PPT教学课件(讲稿)第三章 计算机核心部件及其工作原理.ppt