第一讲 c语言概述
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Absence of restrictions: it more convenient and effective for many tasks Bit-operation: operate to hardware directly.
1.3 simple introduction of C program
1.4 how to run C
How to work?
About C compiler: TC:
1.5 Exercises
Homework: 1.2 C语言的主要用途是什么? 它和其他高 级语言有什么异同?
1.3 写出一个C程序的构成。 1.4 C语言以函数为程序的基本单位,有什 么好处?
C语言:Bell实验室,1972~1973年用其改写UNIX系统
1.2 characters of C
Simple and compact language, easy to use: C-L includes 32 kinds of key-words, 9 kinds of control-statements. A rich set of operators : 34 kinds Rich data structures:integer、float、char、 array、pointer、structure、union ect. Structured control-statements: if…else、 while、do…while、switch、for
``main'' is special - your program begins executing at the beginning of main. This means that every program must have a main somewhere. printf is a library function that prints output, in this case the string of characters between the quotes. The sequence \n in the string is C notation for the newline character, which when printed advances the output to the left margin on the next line.
Experiments: 1.5 请参照本章例题,编写一个C程序,输出以 下信息: ****************************** Very good! ****************************** 1.6 编写一个C程序,输入a、b、c 3个值,输出 其中最大者。 1.7 上机运行本章3个例题,熟悉所用系统的上 机方法与步骤。
A simple example: Main function Ex 1.1 main ( ) Function is enclosed in braces { printf ("This is a C program.\n"); Statements of the function } ----output:This is a C program.
similar to math L; general-purpose; High level flat -independent L
For example:
• Machinቤተ መጻሕፍቲ ባይዱ L
00100011 11101101 01100001 01110110
• assembler
MOV AX, 300H ADD BX, AX MOV [2100H], BX HLT
Why should we study C language? ----C language is used to program system software and application software.
What is computer languages?
Machine Machine instructions Depend on machine, Difficult to study language (1or 0) Mue monic (助记符 assembler ) variable Easier to remember than machine L
&---address “return”----bring the mumber of z return to “main”。
conclusions: 1、 C program is composed of functions。 2、a function consists of two parts: Head:
int max (int ↓ ↓ ↓ ↓
函数类型 函数名
x, ↓
int ↓
y)
函数参数类型 函数参数名 函数参数类型 函数参数名
Body:{ } 3、executing at the beginning of main.
4、Absence of restrictions: 5、comma; 6、library functions 7、comments:/*……*/
Chapter1 C introduction
1.1 1.2 1.3 1.4 1.5 why to be born characters of C simple introduction of C program how to run C Exercises
1.1 why to be born
E1.3 main ( )/* 主函数*/ { int a, b, c; /*声明部分,定义变量*/ scanf ("%d,%d",&a,&b); /*输入变量a和b的值*/ c=max (a,b);/*调用max函数,将得到的值赋给c*/ printf ("max=%d",c); /*输出c的值*/ } int max(int x,int y) /* 定义max函数,函数值为整型, 形 式参数x,y为整型*/ {int z; /* max函数中的声明部分,定义本函数中用到的 变量z为整型*/ if (x>y) z=x; else z=y; return (z); /*将z的值返回,通过max带回调用处*/ }
1.8 上机运行本章习题1.5和1.6。
simplify
BCPL:Cambridge1967(basic combined programming language)
Advanced simplify
B-L:Bell lab,1970. used to write UNIX os on PDP machine
Add data types.
/*……*/ represent “comments”,which in this case explains briefly what the program does. Any characters between /* and */ are ignored by the compiler; they may be used freely to make a program easier to understand. A declaration announces the properties of variables . all variables must be declared before they are used . int a; “%”—indicating where one of the other arguments is to be substituted, and in what form it is to be printed
Ex 1.2 main ( ) /*sum of two nums*/ { int a,b,sum; /*declare variables*/ a=123; b=456; /* C-statements */ sum=a+b; printf ("sum is %d/n", sum); } Output: sum is 579
contents
Chapter8 Functions Chapter9 C Pre-processor Commands Chapter10 Pointer Chapter11 Structures and Unions Chapter12 Bit-operations Chapter13 Files Chapter14 Errors and debugging
Chapter 1
C introduction
By:wangxia e-mail:wangxia1026@163.com
contents
Chapter1 Chapter2 Chapter3 Chapter4 Chapter5 Chapter6 Chapter7 C introduction Algorithm Types, Operators and Expressions Sequence Structure Case Structure Loop Structure Arrays
•C-L
Source-p need to be translated
main( ) { int a, b, c; a=300; b=18; c=a+b; printf(“ a+b= %d\n”, c); }
How does C-L come into being ?
CPL:Cambridge ,1963。(combined programming language)