高级语言程序设计cha.ppt
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_05.gif)
《高级语言程序设计cha.ppt》由会员分享,可在线阅读,更多相关《高级语言程序设计cha.ppt(76页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。
1、A First Book of ANSI CFourth EditionChapter 2Getting Started in C Programming1A First Book of ANSI C,Fourth EditionObjectivesIntroduction to C ProgrammingProgramming StyleData TypesArithmetic Operations2A First Book of ANSI C,Fourth EditionObjectives(continued)Variables and DeclarationsCase Study:Te
2、mperature ConversionCommon Programming and Compiler Errors3A First Book of ANSI C,Fourth EditionIntroduction to C Programming4A First Book of ANSI C,Fourth EditionIntroduction to C Programming(continued)C provides a comprehensive set of functionsStored in a set of files known as the standard library
3、The standard library consists of 15 header files5A First Book of ANSI C,Fourth EditionIntroduction to C Programming(continued)6A First Book of ANSI C,Fourth EditionIntroduction to C Programming(continued)Identifiers7A First Book of ANSI C,Fourth EditionIdentifiersIdentifiers in C consist of three ty
4、pes:Reserved wordsStandard identifiersProgrammer-created identifiers8A First Book of ANSI C,Fourth EditionIdentifiers(continued)Reserved word:word that is predefined by the programming language for a special purpose and can only be used in a specified manner for its intended purposeAlso referred to
5、as keywords in C9A First Book of ANSI C,Fourth EditionIdentifiers(continued)10A First Book of ANSI C,Fourth EditionIdentifiers(continued)Standard identifiers:words predefined in CMost of the standard identifiers are the names of functions that are provided in the C standard libraryIt is good program
6、ming practice to use standard identifiers only for their intended purpose11A First Book of ANSI C,Fourth EditionIdentifiers(continued)12A First Book of ANSI C,Fourth EditionIdentifiers(continued)Programmer-created identifiers:selected by the programmerAlso called programmer-created names Used for na
7、ming data and functionsMust conform to Cs identifier rulesCan be any combination of letters,digits,or underscores(_)subject to the following rules:First character must be a letter or underscore(_)Only letters,digits,or underscores may follow the initial characterBlank spaces are not allowedCannot be
8、 a reserved word13A First Book of ANSI C,Fourth EditionIdentifiers(continued)Examples of invalid C programmer-created names:4ab7calculate totalwhileAll uppercase letters used to indicate a constantA function name must be followed by parentheses An identifier should be descriptive:degToRadians()Bad i
9、dentifier choices:easy,duh,justDoIt C is a case-sensitive languageTOTAL,and total represent different identifiers14A First Book of ANSI C,Fourth EditionThe main()FunctionSometimes referred to as a driver function15A First Book of ANSI C,Fourth EditionThe main()Function(continued)Function header line
10、 Executable statements16A First Book of ANSI C,Fourth EditionThe printf()Functionprintf()formats data and sends it to the standard system display device(i.e.,the monitor)Inputting data or messages to a function is called passing data to the functionprintf(Hello there world!);Syntax:set of rules for
11、formulating statements that are“grammatically correct”for the languageMessages are known as strings in CA string of characters is surrounded by double quotesprintf(Hello there world!);17A First Book of ANSI C,Fourth EditionThe printf()Function(continued)Function arguments18A First Book of ANSI C,Fou
12、rth EditionThe printf()Function(continued)CommentPreprocessor commandHeader fileInvoking or calling the printf()function19A First Book of ANSI C,Fourth EditionThe printf()Function(continued)Output is:Computers,computers everywhereas far as I can CNewline escape sequence20A First Book of ANSI C,Fourt
13、h EditionProgramming Style:IndentationExcept for strings,function names,and reserved words,C ignores all white spaceWhite space:any combination of one or more blank spaces,tabs,or new linesIn standard form:A function name is placed,with the parentheses,on a line by itself starting at the left-hand c
14、ornerThe opening brace follows on the next line,under the first letter of the function nameThe closing function brace is placed by itself at the start of the last line of the function21A First Book of ANSI C,Fourth EditionProgramming Style:Indentation(continued)Within the function itself,all program
15、 statements are indented two spacesIndentation is another sign of good programming practice,especially if the same indentation is used for similar groups of statementsDont do this:intmain()printf(Hello there world!);return 0;22A First Book of ANSI C,Fourth EditionProgramming Style:CommentsComments h
16、elp clarify what a program does,what a group of statements is meant to accomplish,etc.The symbols/*,with no white space between them,designate the start of a comment;the symbols*/designate the end of a comment/*this is a comment*/Comments can be placed anywhere within a program and have no effect on
17、 program executionUnder no circumstances may comments be nested/*this comment is/*always*/invalid*/23A First Book of ANSI C,Fourth EditionProgramming Style:Comments(continued)24A First Book of ANSI C,Fourth EditionData TypesData type:set of values and a set of operations that can be applied to these
18、 valuesBuilt-in data type:is provided as an integral part of the language;also known as primitive type25A First Book of ANSI C,Fourth EditionData Types(continued)26A First Book of ANSI C,Fourth EditionData Types(continued)A literal is an acceptable value for a data typeAlso called a literal value or
19、 constant2,3.6,8.2,and Hello World!are literal values because they literally display their values27A First Book of ANSI C,Fourth EditionData Types(continued)28A First Book of ANSI C,Fourth EditionInteger Data Types29A First Book of ANSI C,Fourth EditionInteger Data Types(continued)int:whole numbers(
20、integers)For example:0,-10,253,-26351Not allowed:commas,decimal points,special symbolschar:stores individual characters(ASCII)For example:A,$,b,!30A First Book of ANSI C,Fourth EditionInteger Data Types(continued)31A First Book of ANSI C,Fourth EditionInteger Data Types(continued)32A First Book of A
21、NSI C,Fourth EditionInteger Data Types(continued)33A First Book of ANSI C,Fourth EditionFloating-Point Data TypesA floating-point value(real number)can be the number zero or any positive or negative number that contains a decimal pointFor example:+10.625,5.,-6.2,3251.92,+2Not allowed:commas,decimal
22、points,special symbolsfloat:single-precision numberdouble:double-precision numberStorage allocation for each data type depends on the compiler(use sizeof()34A First Book of ANSI C,Fourth EditionFloating-Point Data Types(continued)float literal is indicated by appending an f or Flong double is create
23、d by appending an l or L9.234 indicates a double literal9.234f indicates a float literal9.234L indicates a long double literal35A First Book of ANSI C,Fourth EditionFloating-Point Data Types(continued)36A First Book of ANSI C,Fourth EditionExponential NotationIn numerical theory,the term precision t
24、ypically refers to numerical accuracy37A First Book of ANSI C,Fourth EditionExponential Notation(continued)38A First Book of ANSI C,Fourth EditionArithmetic OperationsArithmetic operators:operators used for arithmetic operations:Addition+Subtraction-Multiplication*Division/Modulus Division%Binary op
25、erators require two operandsAn operand can be either a literal value or an identifier that has a value associated with it39A First Book of ANSI C,Fourth EditionArithmetic Operations(continued)A simple binary arithmetic expression consists of a binary arithmetic operator connecting two literal values
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 高级 语言程序设计 cha
![提示](https://www.deliwenku.com/images/bang_tan.gif)
限制150内