C语言双语教学课件c-双语1-reface_第1页
C语言双语教学课件c-双语1-reface_第2页
C语言双语教学课件c-双语1-reface_第3页
C语言双语教学课件c-双语1-reface_第4页
C语言双语教学课件c-双语1-reface_第5页
已阅读5页,还剩31页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

TheCProgrammingLanguage2024/11/131E-mail:lihanjingls@Textbook&ReferencebookTheCProgrammingLanguageBrianW.Kernighan,DennisM.RitchiePrentice-HallInternational,Inc.C程序设计苏晓红编著电子工业出版社C程序设计谭浩强编著清华大学出版社2024/11/132E-mail:lihanjingls@Preface

1 Introduction2 Types,OperatorsandExpressions3 ControlFlow4 FunctionsandProgramStructure5 ArraysandPointers6 Structures7 InputandOutputContents2024/11/133E-mail:lihanjingls@Preface◆NewtermsComputerlanguageProgramProgramming

◆Programs’sConstitution

ThedescriptionofdatumThedescriptionofactions2024/11/134E-mail:lihanjingls@Preface(con)◆Whatistheprogram?datastructure+algorithm=programdatastructure+algorithm+structuredprogrammingmethod+languagetool=program◆ThreebasicstructuresSequentialConditionalLoop数据结构+算法=程序数据结构+算法+结构化程序方法+语言工具=程序顺序选择循环2024/11/135E-mail:lihanjingls@introductionC’sbackgroundC语言发展历史CharacteristicsC语言特点ThesimplestCprogramC程序格式和结构特点HowtorunCprogramC程序上机步骤2024/11/136E-mail:lihanjingls@MachinelagAssemblelagHighlevellangOriented-procedureOriented-objectCPU指令系统,由0、1序列构成的指令码组成如:10000000加10010000减用助记符号描述的指令系统如ADDA,B面向机器的语言程序设计是数据被加工的过程客观世界可以分类,对象是类的实例对象是数据和方法的封装对象间通过发送和接受消息发生联系程序设计关键是定义类,并由类派生对象>>Von.Neumamm冯.诺依曼结构:computercalculatorcontrollermemory主机:I/Odevice:keyboard、screen等CPU1.1C’sbackground2024/11/137E-mail:lihanjingls@◆

TheplaceoftheClanguage

TruedialogueArtificialintelligence“dialogues”Commandlanguages(asinDOS)Problem-orientedlanguages(Fortran,Pascal)Machine-orientedlanguages(BCPL,B,)AssemblylanguagesHardwareC2024/11/138E-mail:lihanjingls@◆TheoriginofClanguageInthemid-1970s,UNIXspreadthroughoutBellLabs.By1980,severalCcompilerswereputforwardonthemarked.Bynow,therearemanyversionsofClanguages.2024/11/139E-mail:lihanjingls@◆Let’stracethedevelopment

Algol60(1960)CPL(1963)BCPL(1967)B(1970)C(1972)where: Belllabaim: UNIXOSdesigner: Ken.Thompson

& Dennis.M.Ritchie2024/11/1310E-mail:lihanjingls@5254565860626466687072747678808284868890929496AdaALGOL60ALGOL68PascalModula-2CPLBCPLBCC++JavaLISPPROLOGCOBOLFORTRAN77PL/1Simula67Smalltalk80BASICANSI-BASICQBASICVBFORTRAN90>2024/11/1311E-mail:lihanjingls@1.2

characteristicsLowlevellangCiseasytolearn.Cprogramsareconcise.Cprogramsarefast.Cprogramsaremodularization.Ccompilersareusuallyfastandconcise.CcompilersandCprogramsrunonallsortsofcomputersUnixhappenstobewritteninC.语言简洁、紧凑、灵活运算符和数据类型丰富程序设计结构化、模块化生成目标代码质量高可移植性好2024/11/1312E-mail:lihanjingls@32keywords:definedandusedbyCautobreakcasecharconstcontinuedefaultdodoubleelseenumexternfloatforgotoifintlongregisterreturnshortsignedsizeofstaticstructswitchtypedefunsignedunionvoidvolatilewhile2024/11/1313E-mail:lihanjingls@9controlflows:if()~else~for()~while()~do~while()continuebreakswitchgotoreturn2024/11/1314E-mail:lihanjingls@34operators:Arithmeticoperators:+-*/%++--Relationaloperators:<<===>>=!=Logicaloperations:!&&||Bitwiseoperators:<<>>~|^&Assignmentoperators:=op=Conditionaloperators:?:comma:,Pointer:*&Sizeofbytes:sizeofTypeconversions:(类型)Structurememberoperators:.->Subscriptoperator:[]others:()-2024/11/1315E-mail:lihanjingls@CTypes数据类型基本类型Basictypes构造类型structures指针类型pointer空类型void定义类型typedefine数值类型字符类型char枚举类型enum整型integer浮点型float单精度型float双精度型double短整型short长整型long整型int数组array结构体structure共用体union2024/11/1316E-mail:lihanjingls@<2024/11/1317E-mail:lihanjingls@1.3ThesimplestCprogramEg1.1Hello,World!/*example1.1ThefirstCProgram*/#include<stdio.h>main(){

printf(“Hello,World!”);}注释comment编译预处理preprocessor函数Mainfunction语句statementTheoutput:Hello,World!2024/11/1318E-mail:lihanjingls@◆Eg1.2a+bmain(){intx,y,z;/*variablesdeclaration*/x=123;y=456;z=x+y;printf(“z=%d\n”,z);}Theoutput:z=579commentOutputthesum2024/11/1319E-mail:lihanjingls@◆Eg1.3areadoublearea(r)main()doubler;{doubler1,r2,s1,s2;{doubles;scanf(“%lf%lf”,&r1,&r2);s=3.14*r*r;s1=area(r1); s2=area(r2);returns;printf(“%lf,%lf\n”,s1,s2);}}Input:1.52.5↙output:7.065,19.626Functioncalling2024/11/1320E-mail:lihanjingls@◆Eg1.4differentofareasdoubleabs(doublex){if(x>=0)returnx;elsereturn–x;}doublepower(doublex,intn){inti=0;doublep=1;L:if(i==n)returnp;p=p*x;i=i+1;gotoL;}2024/11/1321E-mail:lihanjingls@doublearea(doubler){doubles;s=3.14*power(r,2);returns;}main(){doubler1,r2,s1,s2;scanf(“%lf%lf”,&r1,&r2);s1=area(r1);s1=area(r2);printf(“area=%lf\n”,abs(s1-s2));}2024/11/1322E-mail:lihanjingls@格式特点习惯用小写字母,大小写敏感不使用行号,无程序行概念可使用空行和空格常用锯齿形书写格式main(){

……………….………………

…………..…………..

……………….

………………………….

……………….………………..}main(){

inti,j,sum;sum=0;for(i=1;i<10;i++){

for(j=1;j<10;j++){

sum+=i*j;}}

printf(“%d\n”,sum);}优秀程序员的素质之一:使用TAB缩进{}对齐有足够的注释有合适的空行summary2024/11/1323E-mail:lihanjingls@结构特点函数与主函数程序由一个或多个函数组成必须有且只能有一个主函数main()程序执行从main开始,在main中结束,其它函数通过嵌套调用得以执行。程序语句C程序由语句组成用“;”作为语句终止符注释/**/为注释,不能嵌套不产生编译代码例:/*Thisisthemain

/*ofexample1.1*/*/

非法编译预处理命令Summary(con)2024/11/1324E-mail:lihanjingls@Discussion1.1C’sbackgroundWhenwastheClanguagedeveloped?WhatistherelationshipbetweenCandUNIX?Whatarethethreecontrolstructuresforastructuredprogram?1.2TheSimplestCprogramWhatisCprogram’sconstitution?WhatisCfunction’sconstitution?Whatlibraryfunctionhaveyoulearned?Wherewerethevariablesdeclared?2024/11/1325E-mail:lihanjingls@1.3HowtorunCprogramWemustdo:

1.Editit2.Compileit3.RunitItdependsonthesystemweareusing.2024/11/1326E-mail:lihanjingls@目前流行的C语言编译器:MSC、QuickC-------------------------------MicrosoftCo.BorlandC、TurboC-------------------------BorlandCo.WatcomC2024/11/1327E-mail:lihanjingls@file.exeEditCompileLinkExecute2024/11/1328E-mail:lihanjingls@Compile&link2024/11/1329E-mail:lihanjingls@OnUNIXOS$vihello.c$cchello.c$a.out$issystemprompt(othermaybe%)$cc-ohello.outhello.c$mva.outhello.out2024/11/1330E-mail:lihanjingls@DOS(TurboC)C\tc>tcFILE(New,Load,Save,Writeto,Quit)EDITCOMPILERUN(Userscreen[ALT+F5])OPTION(Directory)2024/11/1331E-mail:lihanjingls@基本操作:F10-----调用主菜单F2------存盘F3------打开Alt+F9------CompileCtrl+F9------RunAlt+F5------UserScreen常用热键文本编辑:

-------移动光标PgUp,PgDn------上下翻页Ctrl+PgUp,Ctrl+PgDn------文件首尾HomeEnd

DdeleteInsert

Bkspace块操作:Ctrl+KB-------块开始标记Ctrl+KK--------块结束标记Ctrl+KC-------块拷贝Ctrl+KV--------块移动Ctrl+KY-------块删除Ctrl+KH--------块隐藏程序调试:F8-----StepoverF7-------TraceintoF4-----GotoCursorCtrl+F7--------AddWatchCtrl+F8------ToggleBreakpointCtrl+F2--------ProgramReset窗口操作:F5-----窗口缩放F6-----窗口切换2024/11/1332E-mail:lihanjingls@◆

ACprogramconsistsofoneormorethanonefunctions.◆

ACfunctionconsistsoffunction

name,argumentlistandfunctionbody.◆

ACstatementmusthavea;Briefsummary2024/11/1333E-mail:lihanjingls@◆

printfandscanfarelibraryfunctions,wecanusethemdirectly.◆

Allvariablesmustbedeclared

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论