Presentation is loading. Please wait.

Presentation is loading. Please wait.

程序设计基础.

Similar presentations


Presentation on theme: "程序设计基础."— Presentation transcript:

1 程序设计基础

2 教材、参考书与课时安排 教材 参考书 C程序设计 谭浩强编著 清华大学出版社 C语言程序设计教程 谭浩强 高等教育出版社

3 程序设计基础 第一章 C语言概述 第一章 C语言概述 C语言出现的历史背景 C语言的特点 简单的C程序介绍 C程序上机步骤

4 1.1 C语言出现的历史背景 产生背景 产生过程 C标准 返回主菜单 时间:1972~1973 地点:美国贝尔实验室 目的:UNIX操作系统
设计人: Ken.Thompson和Dennis.M.Ritchie C标准 标准C: K&R合著《The C Programming Language》 ANSI C: 1983年 87 ANSI C: 1987年 1990年国际标准的ANSI C 返回主菜单

5 ALGOL60 英国剑桥大学 CPL(Combined Programming Language) 1967 英国剑桥大学 Matin Richards BCPL(Basic Combined Programming Languege) 1970 美国BELL 实验室的Ken Thompson 简化了BCPL 提出B语言,并用B写了第一个UNIX操作系统。

6 1.2 C语言的特点 语言简洁、紧凑、灵活 运算符和数据类型丰富 程序设计结构化、模块化 生成目标代码质量高 可移植性好 返回主菜单

7 32个关键字:(由系统定义,不能重作其它定义)
auto break case char const continue default do double else enum extern float for goto if int long register Return short signed sizeof statec structt switch typedef unsigned union viod volatile while

8 9种控制语句: if( )~else~ for( )~ while( )~ do~while( ) Continue Break
Switch Goto Return

9 34种运算符: 算术运算符 + - * / % ++ -- 关系运算符 < <= == > >= != 逻辑运算符
+ - * / % 关系运算符 < <= == > >= != 逻辑运算符 ! && || 位运算符 << >> ~ | ^ & 赋值运算符 = 及其扩展 条件运算符 ?: 逗号运算符 , 指针运算符 * & 求字节数 sizeof 强制类型转换 (类型) 分量运算符 . -> 下标运算符 [] 其它 ( ) -

10 C 基本类型 构造类型 指针类型 空类型void 定义类型typedef 数值类型 字符类型char 枚举类型enum 整 型 浮点型 单精度型float 双精度型double 短整型short 长整型long 整型int 数组 结构体struct 共用体union

11 1.3 简单的C程序介绍 例1.1 显示字符串 Hello,World!
/* example1.1 The first C Program*/ #include <stdio.h> main() { printf(“Hello,World!”); } 执行结果: Hello,World!

12 /* example1.1 calculate the sum of a and b*/ #include <stdio.h>
例1.2 /* example calculate the sum of a and b*/ #include <stdio.h> /* This is the main program */ main() { int a,b,sum; a=10; b=24; sum=add(a,b); printf(”sum= %d\n",sum); } /* This function calculates the sum of x and y */ int add(int x,int y) { int z; z=x+y; return(z);} 执行结果: sum=34

13 格式特点 习惯用小写字母,大小写敏感 不使用行号,无程序行概念 main( ) 可使用空行和空格 { int i , j , sum;
程序设计基础 第一章 C语言概述 格式特点 习惯用小写字母,大小写敏感 不使用行号,无程序行概念 可使用空行和空格 常用锯齿形书写格式 main( ) { int i , j , sum; sum=0; for(i=1; i<10;i++) for(j=1;j<10;j++) sum+=i*j ; } printf(“%d\n”,sum);

14 结构特点 函数与主函数 程序语句 注释 非法 例: /*This is the main /* of example1.1*/ */
程序设计基础 第一章 C语言概述 结构特点 函数与主函数 程序由一个或多个函数组成 必须有且只能有一个主函数main() 程序执行从main开始,在main中结束,其它函数通过嵌套调用得以执行。 程序语句 C程序由语句组成 用“;”作为语句终止符 注释 /* */为注释,不能嵌套 不产生编译代码 例: /*This is the main /* of example1.1*/ */ 非法 编译预处理命令 返回主菜单

15 1.4 C程序的上机步骤 C程序开发步骤 编辑 编译 链接 执行 程序代码的录入, 生成源程序*.c 语法分析查错,翻译
生成目标程序*.obj 与其它目标程序或库 链接装配,生成可执行 程序*.exe file.exe

16 The end


Download ppt "程序设计基础."

Similar presentations


Ads by Google