1、2022-4-25E-mail:1The C Programming Language2022-4-25E-mail:2lThe C Programming Language Brian W.Kernighan , Dennis M.Ritchie Prentice-Hall International , Inc.lC 程序设计 苏晓红 编著 电子工业出版社lC 程序设计 谭浩强 编著 清华大学出版社2022-4-25E-mail:3Preface 1 Introduction2 Types,Operators and Expressions3 Control Flow4 Functions
2、 and Program Structure5 Arrays and Pointers 6 Structures7 Input and OutputContents2022-4-25E-mail:4l New termsComputer languageProgramProgramming l Programss Constitution The description of datumThe description of actions2022-4-25E-mail:5l What is the program?data structure+algorithm=programdata str
3、ucture+algorithm+structured programming method+language tool= programl Three basic structuresSequentialConditionalLoop数据结构+算法=程序数据结构+算法+结构化程序方法+语言工具=程序顺序选择循环2022-4-25E-mail:6Cs background C语言发展历史Characteristics C语言特点The simplest C program C程序格式和结构特点How to run C program C程序上机步骤2022-4-25E-mail:7Machin
4、e lagAssemble lagHigh level langOriented-procedureOriented-objectCPU指令系统,由0、1序列构成的指令码组成如:10000000 加 10010000 减用助记符号描述的指令系统如 ADD A, B面向机器的语言程序设计是数据被加工的过程客观世界可以分类,对象是类的实例对象是数据和方法的封装对象间通过发送和接受消息发生联系程序设计关键是定义类,并由类派生对象Von.Neumamm冯.诺依曼结构:computercalculatorcontrollermemory主机:I/O device:keyboard、screen等CPU2
5、022-4-25E-mail:8 The place of the C languageTrue dialogueArtificial intelligence “ dialogues”Command languages(as in DOS)Problem-oriented languages(Fortran, Pascal)Machine-oriented languages(BCPL,B,)Assembly languagesHardwareC2022-4-25E-mail:9 The origin of C languageIn the mid-1970s,UNIX spread thr
6、oughout Bell Labs.By 1980,several C compilers were put forward on the marked.By now,there are many versions of C languages.2022-4-25E-mail:10 Lets trace the development Algol60 (1960) CPL (1963) BCPL (1967) B (1970) C (1972)lwhere: Bell lablaim: UNIX OSldesigner: Ken.Thompson &Dennis.M.Ritchie2022-4
7、-25E-mail:1152 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96AdaALGOL60ALGOL68PascalModula-2CPLBCPL BCC+JavaLISPPROLOGCOBOLFORTRAN77PL/1Simula 67Smalltalk 80BASICANSI-BASICQBASIC VBFORTRAN902022-4-25E-mail:12l1.2 characteristicsLow level langC is easy to learn. C programs are conc
8、ise. C programs are fast. C programs are modularization.C compilers are usually fast and concise. C compilers and C programs run on all sorts of computersUnix happens to be written in C.语言简洁、紧凑、灵活运算符和数据类型丰富程序设计结构化、模块化生成目标代码质量高可移植性好2022-4-25E-mail:1332 keywords:defined and used by Cauto break case ch
9、ar constcontinue default do double elseenum extern float for gotoif int long register returnshort signed sizeof static structswitch typedef unsigned union voidvolatile while2022-4-25E-mail:149 9 controlflowscontrolflows:if( )elsefor( )while( )dowhile( )continuebreakswitchgotoreturn2022-4-25E-mail:15
10、34 34 operatorsoperators:Arithmetic operators:+ - * / % + -Relational operators: = !=Logical operations:! & |Bitwise operators: | &Assignment operators:= op=Conditional operators:?:comma :,Pointer :* &Size of bytes :sizeofType conversions :(类型)Structure member operators: . -Subscript operator:others
11、 :( ) -2022-4-25E-mail:16CTypes数据类型基本类型Basic types构造类型structures指针类型pointer空类型void定义类型 type define数值类型字符类型char枚举类型enum整 型integer浮点型float单精度型float双精度型double短整型short长整型long整型int数组 array结构体structure共用体union2022-4-25E-mail:172022-4-25E-mail:18Eg 1.1 Hello,World!/* example1.1 The first C Program*/#includ
12、e main() printf(“Hello,World!”);注释comment编译预处理preprocessor函数Main function语句statementThe output:Hello,World!2022-4-25E-mail:19 Eg1.2 a + bmain()int x,y,z; /*variables declaration*/x=123;y=456;z=x+y;printf(“z=%dn”,z);The output:z=579commentOutput the sum2022-4-25E-mail:20 Eg1.3 areadouble area(r) main
13、()double r; double r1,r2,s1,s2;double s; scanf(“%lf%lf”,&r1,&r2);s=3.14*r*r; s1=area(r1); s2=area(r2);return s; printf(“%lf,%lfn”,s1,s2); Input: 1.5 2.5 output:7.065,19.626Function calling2022-4-25E-mail:21 Eg1.4 different of areasdouble abs(double x) if (x=0) return x; else return x;double power(do
14、uble x,int n)int i=0;double p=1;L:if (i=n) return p;p=p*x;i=i+1;goto L;2022-4-25E-mail:22double area(double r) double s; s=3.14*power(r,2); return s; main()double r1,r2,s1,s2; scanf(“%lf%lf”,&r1,&r2);s1=area(r1);s1=area(r2);printf(“area=%lfn”,abs(s1-s2);2022-4-25E-mail:23格式特点l习惯用小写字母,大小写敏感l不使用行号,无程序
15、行概念l可使用空行和空格l常用锯齿形书写格式main( ) . . . . . . .main( ) int i , j , sum; sum=0; for(i=1; i10;i+) for(j=1;jtc to,Quit)EDITCOMPILERUN(User screen ALT+F5)OPTION(Directory)2022-4-25E-mail:32基本操作:F10-调用主菜单F2-存盘F3-打开Alt+F9-CompileCtrl+F9-RunAlt+F5-User Screenl常用热键文本编辑:-移动光标PgUp,PgDn-上下翻页Ctrl+PgUp,Ctrl+PgDn-文件首
16、尾Home End Ddelete Insert Bkspace块操作:Ctrl+KB-块开始标记 Ctrl+KK-块结束标记Ctrl+KC-块拷贝 Ctrl+KV-块移动Ctrl+KY-块删除 Ctrl+KH-块隐藏程序调试:F8-Step over F7-Trace intoF4-Goto Cursor Ctrl+F7-Add WatchCtrl+F8-Toggle Breakpoint Ctrl+F2-Program Reset窗口操作:F5-窗口缩放F6-窗口切换2022-4-25E-mail:33 A C program consists of one or more than on
17、e functions. A C function consists of function name,argument list and function body. A C statement must have a ;Brief summary2022-4-25E-mail:34 printf and scanf are library functions, we can use them directly. All variables must be declared before they are used,then initialized. Control character wi
18、th % in printf is consistent with variables type Dont go beyond the limit of the variablesBrief summary2022-4-25E-mail:35lUses the formula c=(5/9)(f-32) to print the Celsius temperatures c for the specific Fahrenheit f .double%lfl If x and y are all integers,x=123,y=456,please output their product.What is the biggest integer for the n-bits number?p 经常不断地学习,你就什么都知道。你知道得越多,你就越有力量p Study Constantly, And You Will Know Everything. The More You Know, The More Powerful You Will Be写在最后谢谢大家荣幸这一路,与你同行ItS An Honor To Walk With You All The Way演讲人:XXXXXX 时 间:XX年XX月XX日