高级语言程序设计cha.ppt
《高级语言程序设计cha.ppt》由会员分享,可在线阅读,更多相关《高级语言程序设计cha.ppt(76页珍藏版)》请在三一办公上搜索。
1、A First Book of ANSI CFourth Edition,Chapter 2Getting Started in C Programming,A First Book of ANSI C,Fourth Edition,2,Objectives,Introduction to C ProgrammingProgramming StyleData TypesArithmetic Operations,A First Book of ANSI C,Fourth Edition,3,Objectives(continued),Variables and DeclarationsCase
2、 Study:Temperature ConversionCommon Programming and Compiler Errors,A First Book of ANSI C,Fourth Edition,4,Introduction to C Programming,A First Book of ANSI C,Fourth Edition,5,Introduction to C Programming(continued),C provides a comprehensive set of functionsStored in a set of files known as the
3、standard libraryThe standard library consists of 15 header files,A First Book of ANSI C,Fourth Edition,6,Introduction to C Programming(continued),A First Book of ANSI C,Fourth Edition,7,Introduction to C Programming(continued),A First Book of ANSI C,Fourth Edition,8,Identifiers,Identifiers in C cons
4、ist of three types:Reserved wordsStandard identifiersProgrammer-created identifiers,A First Book of ANSI C,Fourth Edition,9,Identifiers(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 purpo
5、seAlso referred to as keywords in C,A First Book of ANSI C,Fourth Edition,10,Identifiers(continued),A First Book of ANSI C,Fourth Edition,11,Identifiers(continued),Standard identifiers:words predefined in CMost of the standard identifiers are the names of functions that are provided in the C standar
6、d libraryIt is good programming practice to use standard identifiers only for their intended purpose,A First Book of ANSI C,Fourth Edition,12,Identifiers(continued),A First Book of ANSI C,Fourth Edition,13,Identifiers(continued),Programmer-created identifiers:selected by the programmerAlso called pr
7、ogrammer-created names Used for naming 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 characterBla
8、nk spaces are not allowedCannot be a reserved word,A First Book of ANSI C,Fourth Edition,14,Identifiers(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 sho
9、uld be descriptive:degToRadians()Bad identifier choices:easy,duh,justDoIt C is a case-sensitive languageTOTAL,and total represent different identifiers,A First Book of ANSI C,Fourth Edition,15,The main()Function,A First Book of ANSI C,Fourth Edition,16,The main()Function(continued),Function header l
10、ine,Executable statements,A First Book of ANSI C,Fourth Edition,17,The printf()Function,printf()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 rul
11、es for 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!);,A First Book of ANSI C,Fourth Edition,18,The printf()Function(continued),Function arguments,A First Book of
12、ANSI C,Fourth Edition,19,The printf()Function(continued),Comment,Preprocessor command,Header file,Invoking or calling the printf()function,A First Book of ANSI C,Fourth Edition,20,The printf()Function(continued),Output is:Computers,computers everywhereas far as I can C,Newline escape sequence,A Firs
13、t Book of ANSI C,Fourth Edition,21,Programming Style:Indentation,Except 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
14、starting at the left-hand cornerThe 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 function,A First Book of ANSI C,Fourth Edition,22,Programming Style:Indentation(continued),Within
15、the function itself,all program 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;,A First Book of ANSI C,Fourth Edition,23,Pr
16、ogramming Style:Comments,Comments help 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 wit
17、hin a program and have no effect on program executionUnder no circumstances may comments be nested/*this comment is/*always*/invalid*/,A First Book of ANSI C,Fourth Edition,24,Programming Style:Comments(continued),A First Book of ANSI C,Fourth Edition,25,Data Types,Data type:set of values and a set
18、of operations that can be applied to these valuesBuilt-in data type:is provided as an integral part of the language;also known as primitive type,A First Book of ANSI C,Fourth Edition,26,Data Types(continued),A First Book of ANSI C,Fourth Edition,27,Data Types(continued),A literal is an acceptable va
19、lue for a data typeAlso called a literal value or constant2,3.6,8.2,and Hello World!are literal values because they literally display their values,A First Book of ANSI C,Fourth Edition,28,Data Types(continued),A First Book of ANSI C,Fourth Edition,29,Integer Data Types,A First Book of ANSI C,Fourth
20、Edition,30,Integer Data Types(continued),int:whole numbers(integers)For example:0,-10,253,-26351Not allowed:commas,decimal points,special symbolschar:stores individual characters(ASCII)For example:A,$,b,!,A First Book of ANSI C,Fourth Edition,31,Integer Data Types(continued),A First Book of ANSI C,F
21、ourth Edition,32,Integer Data Types(continued),A First Book of ANSI C,Fourth Edition,33,Integer Data Types(continued),A First Book of ANSI C,Fourth Edition,34,Floating-Point Data Types,A floating-point value(real number)can be the number zero or any positive or negative number that contains a decima
22、l pointFor example:+10.625,5.,-6.2,3251.92,+2Not allowed:commas,decimal points,special symbolsfloat:single-precision numberdouble:double-precision numberStorage allocation for each data type depends on the compiler(use sizeof(),A First Book of ANSI C,Fourth Edition,35,Floating-Point Data Types(conti
23、nued),float literal is indicated by appending an f or Flong double is created by appending an l or L9.234 indicates a double literal9.234f indicates a float literal9.234L indicates a long double literal,A First Book of ANSI C,Fourth Edition,36,Floating-Point Data Types(continued),A First Book of ANS
24、I C,Fourth Edition,37,Exponential Notation,In numerical theory,the term precision typically refers to numerical accuracy,A First Book of ANSI C,Fourth Edition,38,Exponential Notation(continued),A First Book of ANSI C,Fourth Edition,39,Arithmetic Operations,Arithmetic operators:operators used for ari
25、thmetic operations:Addition+Subtraction-Multiplication*Division/Modulus Division%Binary operators require two operandsAn operand can be either a literal value or an identifier that has a value associated with it,A First Book of ANSI C,Fourth Edition,40,Arithmetic Operations(continued),A simple binar
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 高级 语言程序设计 cha
链接地址:https://www.31ppt.com/p-6358482.html