#黑日工作室 #
非常感谢 天津城市建设学院 周锦姝老师教材、参考书与课时安排
– 教材
C程序设计 谭浩强编著 清华大学出版社
– 参考书
The C Programming Language
(美) Brian W.Kernighan Dennis M.Ritchie 著
C语言教程 (英文版 ) A Book On C
(美) Al Kelley Ira Pohl 著 机械工业出版社
– 课时安排授课,28学时
C综合编程训练,28学时
– 上机安排上机地点:计算机系机房( 12楼)
课程要求
课前请做好预习
保持课堂安静,头脑清醒,思维活跃,积极发言
认真、独立、按时完成并提交作业,作业必须经上机调试通过
重视上机实践,有效利用宝贵的上机时间,发现上机时间上网,按缺席一次处理
分值安排 考试成绩 70% 平时成绩 30%
Chapter 1 An Overview of C
The history of C
The feature of C
The pattern of a C program
Running a C program
The C Programming Language Chapter 1 An Overview of C
1.2 The feature of C
– C is terse,it has fewer keywords
– C has a lot of operators and data types
– C is structured and modular.
– C is the basis for C++ and Java
– C is portable.Code written on one machine can
be easily moved to another.
< >
>
>
>>
The C Programming Language Chapter 1 An Overview of C
32 keywords,(由系统定义,不能重作其它定义 )
auto break case char const
continue default do double else
enum extern float for goto
if int long register return
short signed sizeof static struct
switch typedef unsigned union void
volatile while
<
The C Programming Language Chapter 1 An Overview of C
statements(语句 ):
Labeled statements(带标号语句 )
Expression statements(表达式语句 )
Compound statements(复合语句 )
Selection statements(选择语句 )
if (expression) statement
if (expression) statement else statement
switch (expression) statement
Iteration
while (expression) statement
do while (expression)
for (exp1;exp2;exp3) statement
Jump statements(跳转语句 )
continue;
break;
goto identifier;
return expression;<
The C Programming Language Chapter 1 An Overview of C
34 operators(运算符 ):
Arithmetic(算术 ) operators,+ - * / % ++ --
Relational(关系 ) operators,< <= == > >= !=
Logical(逻辑 ) operators,! && ||
Bitwise(位 ) operators,<< >> ~ | ^ &
Assighment(赋值 ) operators,= += -=
Conditional(条件 ) operators,?,
Comma(逗号 ) operators,,
Address(地址 ) operators,* &
Sizeof (求字节数 ) operators,sizeof
Casts(强制类型转换 ),(type-name)
Structure member(分量 ) operators,,->
Subscript(下标 ) operators,[ ]
others,( ) -
<
The C Programming Language Chapter 1 An Overview of C
Data
Types Constructed
types
pointers
void
定义类型 typedef
Character types char
enum
integer
floating single precision floating point float
double precision floating point double
short int
long int
int
arrays
structures
unions
<
The C Programming Language Chapter 1 An Overview of C
Basic
types
Arithmetic
types
1.3The pattern of a C program
Exampl 1.1 the first c program Hello,World!
/* example1.1 The first C Program*/
#include <stdio.h>
main()
{
printf(“Hello,World!”);
}
>
notation
Include information
about standard library
define a function named main
statement
output:
Hello,World!
The C Programming Language Chapter 1 An Overview of C
exp1.2 /* example1.1 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
函数语句预处理命令注释
>
The C Programming Language Chapter 1 An Overview of C
– 格式特点
习惯用 小写 字母,大小写敏感
不使用行号,无程序行 概念
可使用空行和空格
常用 锯齿形 书写格式
< >
main( )
{ ……………….
………………
…………..
…………..
………
……….
……………
…………….
……………….
………………..
}
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);
}
优秀程序员的素质之一,
使用 TAB缩进
{}对齐
有足够的注释
有合适的空行
The C Programming Language Chapter 1 An Overview of C
– 结构特点
函数与主函数
– 程序由一个或多个函数组成
– 必须有且只能有一个主函数 main()
– 程序执行从 main开始,在 main中结束,其它函数通过嵌套调用得以执行。
程序语句
– C程序由语句组成
– 用,;”作为语句终止符
注释
– /* */为注释,不能嵌套
– 不产生编译代码
< >
例,/*This is the main /* of example1.1*/
*/
非法编译预处理命令
The C Programming Language Chapter 1 An Overview of C
编辑链接编译执行
§ 1.4 C程序的上机步骤
C程序开发步骤
< >
开 始编 辑编 译连 接执 行有错?
结果正确?
结 束有源程序
f i l e,c
目标程序
f i l e,obj
库函数和其它目标程序可执行目标程序无正确不正确
file.exe
程序代码的录入,
生成源程序 *.c
语法分析查错,翻译生成目标程序 *.obj
与其它目标程序或库链接装配,生成可执行程序 *.exe
′ 3ì Dò ±ê 3ì Dò?é?′ D 3ì Dò
ú èY 3ì Dò éè óú óú ó
é?′ D 2é ò? 2é òé ò?
t oó ×,c,o b j,e x e
The C Programming Language Chapter 1 An Overview of C
– Turbo C集成开发环境
配置要求
– UNIX,PC-DOS,MS-DOS,UCDOS操作系统
– 硬盘容量约 2M,448K RAM运行空间
安装 Turbo C
– 创建子目录
– Install
– 若不是可安装盘,将文件拷贝到对应的目录下
TC
*.* INCLUDE LIB
*.* SYS *.*
< >
The C Programming Language Chapter 1 An Overview of C
进入 Turbo C
– D:\TC>TC.exe?
– 主控菜单
文件操作 FILE,New Load Save Write to
编辑操作 EDIT:插入 /修改 块 查找 /替换
编译链接 COMPILE LINK MAKE
执行 RUN
退出 Turbo C
– Alt +x
– Alt+F,Q
帮助 Help
– F1
– Ctrl+F1
< >
The C Programming Language Chapter 1 An Overview of C
基本操作:
F10-----调用主菜单
F2------存盘
F3------打开
Alt+F9------Compile
Ctrl+F9------Run
Alt+F5------User Screen
常用热键文本编辑:
-------移动光标
PgUp,PgDn------上下翻页
Ctrl+PgUp,Ctrl+PgDn------文件首尾
Home End
Ddelete Insert
Bkspace
块操作,
Ctrl+KB-------块开始标记 Ctrl+KK--------块结束标记
Ctrl+KC-------块拷贝 Ctrl+KV--------块移动
Ctrl+KY-------块删除 Ctrl+KH--------块隐藏程序调试:
F8-----Step over F7-------Trace into
F4-----Goto Cursor Ctrl+F7--------Add Watch
Ctrl+F8------Toggle Breakpoint Ctrl+F2--------Program Reset
窗口操作:
F5-----窗口缩放
F6-----窗口切换
The C Programming Language Chapter 1 An Overview of C