Chapter 3 Data types, Operators, and Expressions 口 Byte and Bit 765432 0 Memory以Byte为单元组成 每个Byte有一个 Address 一个Byte一般由8个Bt组成 每个Bit的值是0或1 765432 23456789 10
6 ❑Byte and Bit • Memory以Byte为单元组成 • 每个Byte有一个Address • 一个Byte一般由8个Bit组成 • 每个Bit的值是0或1 7 6 5 4 3 2 1 0 0 1 2 3 4 5 6 7 8 9 10 ……... < > 7 6 4 3 2 5 1 Chapter 3 Data types , Operators , and Expressions
Chapter 3 Data types, Operators, and Expressions 数值的表示方法——原码、反码和补码 原码:最高位为符号位,其余各位为数值本身的绝对值 反码: 正数:反码与原码相同 负数:符号位为1,其余位对原码取反 补码: 负数:最高位为1,其余位为原码取反,再对整个数加1 正数:原码、反码、补码相同 (用一字节表示数) 原码 反码 补码 7 00000111 00000111 00000111 7 10000111 11111000 11111001
7 – 数值的表示方法——原码、反码和补码 • 原码:最高位为符号位,其余各位为数值本身的绝对值 • 反码: – 正数:反码与原码相同 – 负数:符号位为1,其余位对原码取反 • 补码: – 负数:最高位为1,其余位为原码取反,再对整个数加1 – 正数:原码、反码、补码相同 < 原码 反码 补码 +7 00000111 00000111 00000111 -7 10000111 11111000 11111001 (用一字节表示数) Chapter 3 Data types , Operators , and Expressions
Chapter 3 Data types, Operators, and Expressions 3.1 Data types short int integer Int Arithmetic long int types Basic single precision floating point float floating type double precision floating point double Character types char 数据类型决定 enum 1.数据占内存字节数 Data 2.数据取值范围 Types arrays 3.其上可进行的操作 Constructed structures types unIons pointers VOI d
8 3.1 Data types < > 数据类型决定: 1. 数据占内存字节数 2. 数据取值范围 3. 其上可进行的操作 Chapter 3 Data types , Operators , and Expressions Data Types Constructed types pointers void Character types char enum integer floating single precision floating point float double precision floating point double short int long int int arrays structures unions Basic types Arithmetic types
Chapter 3 Data types, Operators, and Expressions Basic types Type Keywords Bits Available range of values (signed)int 16 -32768~32767 (Signed )short 16 -32768~32767 (signed )long 32 -2147483648~2147483647 integer unsigned int 16 0~65535 unsigned short 16 0~65535 unsigned long 32 0~4294967295 float 32 le-37~le38 floating double 64 le-307~le308 long double 80 le-4931~1e4932 character char 说明∶数据类型所占位数随机器硬件不同而不同,上表以微机为例 ●o9
9 Basic types < > Type Keywords Bits Available range of values integer (signed)int 16 -32768~32767 (signed)short 16 -32768~32767 (signed)long 32 -2147483648~2147483647 unsigned int 16 0~65535 unsigned long 32 0~4294967295 unsigned short 16 0~65535 float 32 1e-37~1e38 double 64 1e-307~1e308 char 8 说明:数据类型所占位数随机器硬件不同而不同,上表以微机为例: long double 80 1e-4931~1e4932 character Chapter 3 Data types , Operators , and Expressions
Chapter 3 Data types, Operators, and Expressions b3.2 Constants and variables Identifiers(标志符) An identifier is a sequence of letters, digits and underscore The first character must be a letter or an underscore Upper and lower case letters are different Can not use keywords as variable names It's wise to choose variable names that are related to the 例:判断下列标识符号合法性 sum Sum M.D.John day Date 3days student name #33 lotus 1 2 3 char a>b above $123 10
10 3.2 Constants and Variables – Identifiers (标志符) • An identifier is a sequence of letters , digits and underscore _ ; • The first character must be a letter or an underscore _; • Upper and lower case letters are different ; • Can not use keywords as variable names ; • It’s wise to choose variable names that are related to the purpose of the variable ; Notice : such as l and I, o and 0…….. 例:判断下列标识符号合法性 sum Sum M.D.John day Date 3days student_name #33 lotus_1_2_3 char a>b _above $123 < > M.D.John 3days #33 char a>b $123 Chapter 3 Data types , Operators , and Expressions