国外C语言程序设计英文课件lecture

上传人:平*** 文档编号:48602676 上传时间:2018-07-18 格式:PPT 页数:37 大小:160.02KB
返回 下载 相关 举报
国外C语言程序设计英文课件lecture_第1页
第1页 / 共37页
国外C语言程序设计英文课件lecture_第2页
第2页 / 共37页
国外C语言程序设计英文课件lecture_第3页
第3页 / 共37页
国外C语言程序设计英文课件lecture_第4页
第4页 / 共37页
国外C语言程序设计英文课件lecture_第5页
第5页 / 共37页
点击查看更多>>
资源描述

《国外C语言程序设计英文课件lecture》由会员分享,可在线阅读,更多相关《国外C语言程序设计英文课件lecture(37页珍藏版)》请在金锄头文库上搜索。

1、Computer ProgrammingLecture 2 02.10.2012Lecture 2: OutlineVariables, Data Types, and Arithmetic Expressions K- ch.4 Working with Variables Understanding Data Types and Constants The Basic Integer Type int The Floating Number Type float The Extended Precision Type double The Single Character Type cha

2、r The Boolean Data Type _Bool Storage sizes and ranges Type Specifiers: long, long long, short, unsigned, and signed Working with Arithmetic Expressions Integer Arithmetic and the Unary Minus Operator The Modulus Operator Integer and Floating-Point Conversions Combining Operations with Assignment: T

3、he Assignment Operators Types _Complex and _Imaginary Variables Programs can use symbolic names for storing computation data Variable: a symbolic name for a memory location programmer doesnt have to worry about specifying (or even knowing) the value of the locations address In C, variables have to b

4、e declared before they are used Variable declaration: symbolic name(identifier), type Declarations that reserve storage are called definitions The definition reserves memory space for the variable, but doesnt put any value there Values get into the memory location of the variable by initialization o

5、r assignementVariables - Examplesint a; / declaring a variable of type intint sum, a1,a2; / declaring 3 variablesint x=7; / declaring and initializing a variable a=5; / assigning to variable a the value 5a1=a; / assigning to variable a1 the value of aL-valueR-valuea1=a1+1; / assigning to variable a1

6、 the value of a1+1/ (increasing value of a1 with 1)Variable declarationsData type Variable nameWhich data types are possible in C ? Which variable names are allowed in C ? Variable namesRules for valid variable names (identifiers) in C : Name must begin with a letter or underscore ( _ ) and can be f

7、ollowed by any combination of letters, underscores, or digits. Any name that has special significance to the C compiler (reserved words) cannot be used as a variable name. Examples of valid variable names: Sum, pieceFlag, I, J5x7, Number_of_moves, _sysflag Examples of invalid variable names: sum$val

8、ue, 3Spencer, int. C is case-sensitive: sum, Sum, and SUM each refer to a different variable ! Variable names can be as long as you want, although only the first 63 (or 31) characters might be significant. (Anyway, its not practical to use variable names that are too long) Choice of meaningful varia

9、ble names can increase the readability of a programData types Basic data types in C: int, float, double, char, and _Bool.Data type int: can be used to store integer numbers (values with no decimal places) Data type type float: can be used for storing floating-point numbers (values containing decimal

10、 places). Data type double: the same as type float, only with roughly twice the precision. Data type char: can be used to store a single character, such as the letter a, the digit character 6, or a semicolon. Data type _Bool: can be used to store just the values 0 or 1 (used for indicating a true/fa

11、lse situation). This type has been added by the C99 standard (was not in ANSI C) Example: Using data types#include int main (void) int integerVar = 100; float floatingVar = 331.79; double doubleVar = 8.44e+11; char charVar = W; _Bool boolVar = 0; printf (“integerVar = %in“, integerVar); printf (“flo

12、atingVar = %fn“, floatingVar); printf (“doubleVar = %en“, doubleVar); printf (“doubleVar = %gn“, doubleVar); printf (“charVar = %cn“, charVar); printf (“boolVar = %in“, boolVar); return 0; The basic data type int Examples of integer constants: 158, 10, and 0 No embedded spaces are permitted between

13、the digits, and values larger than 999 cannot be expressed using commas. (The value 12,000 is not a valid integer constant and must be written as 12000.) Integer values can be displayed by using the format characters %i in the format string of a printf call. Also the %d format characters can be used

14、 to display an integer (Kernighanprintf(“%i %#X %#on“, x,x,x);0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0storage (binary)programdisplay“%i”“%#X”160X10“%#o”020The floating number type floatA variable declared to be of type float can be used for storing values containing decimal places. Examples of floating-point

15、 constants : 3., 125.8, .0001 To display a floating-point value at the terminal, the printf conversion characters %f are used. Floating-point constants can also be expressed in scientific notation.The value 1.7e4 represents the value 1.7 104. The value before the letter e is known as the mantissa, w

16、hereas the value that follows is called the exponent. This exponent, which can be preceded by an optional plus or minus sign, represents the power of 10 by which the mantissa is to be multiplied. To display a value in scientific notation, the format characters %e should be specified in the printf format string.

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 中学教育 > 教学课件

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号