DATA TYPES 基本粪型 Basie Types 基本数据类型( Basic data types): 字符型(char) a single byte, capable of holding one character 基本整型(int an integer, typically reflecting the natural size of integers on the host machine 单精度浮点型(foat) single-precision floating point 双精度浮点型( double) double-precision floating point 壽此外,有几个修饰符( qualifiers)可以加到基本数据类型上 short ong signed unsigned 第二讲擲粪型、算莓和表达丸「
基本类型 Basic Types 基本数据类型(Basic data types): – 字符型(char) • a single byte, capable of holding one character – 基本整型(int) • an integer, typically reflecting the natural size of integers on the host machine – 单精度浮点型(float) • single-precision floating point – 双精度浮点型(double) • double-precision floating point 此外,有几个修饰符(qualifiers)可以加到基本数据类型上 • short • long • signed • unsigned DaTa TYPes 第二讲 数据类型、运算符和表达式 目 录
CONSTANTS 幸量 Constants 常量( Constants) 常量是在程序执行过程中其值不变化的量 Constants are program elements that do not change their values during the course of program execution. 口C语言有以下几种类型的常量: 整型常量( integer constants) 浮点型常量( floating- point constants) 字符型常量( character constants) 字符串型常量( string constants) 第二讲擲粪型、算莓和表达丸「
常量 Constants 常量(Constants) – 常量是在程序执行过程中其值不变化的量。 – Constants are program elements that do not change their values during the course of program execution. C语言有以下几种类型的常量: – 整型常量(integer constants) – 浮点型常量(floating-point constants) – 字符型常量(character constants) – 字符串型常量(string constants) ConsTanTs 第二讲 数据类型、运算符和表达式 目 录
CONSTANTS 符号常量 mboc Constants 口符号常量 符号常量是用一个标识符表示的常量。 口定义规则 define <symbolic constant name> <string> Symbolic constants are handled by the c preprocessor and are defined using the #define construct. It is a good programming practice to use symbolic constants where possible. This enables certain changes be made with a minimal amount of efforts define MAXSIZE 20 define WElCoME "Welcome to you!! n define PI 3.14 第二讲擲粪型、算莓和表达丸「
符号常量 Symbolic Constants 符号常量 – 符号常量是用一个标识符表示的常量。 定义规则 #define <symbolic_constant_name> <string> Symbolic constants are handled by the C preprocessor and are defined using the #define construct. It is a good programming practice to use symbolic constants where possible. This enables certain changes be made with a minimal amount of efforts. ConsTanTs 第二讲 数据类型、运算符和表达式 目 录 #define MAXSIZE 20 #define WELCOME "Welcome to you!" #define PI 3.14
CONSTANTS 例21符号常量的应用 Symbolic constants Application 日Prob|em Calculate area of a circle L Program /* Example 2-1 CW02-01C Calculate area of a circle. * #include <stdio. h> define PI 3.14 area void maino f1。atx,area; scanf (of&r) area=P工*工*r; printf("area=f",area)i 3.140000 第二讲擲粪型、算莓和表达丸「
例2-1 符号常量的应用 Symbolic Constants Application Problem – Calculate area of a circle. Program ConsTanTs 第二讲 数据类型、运算符和表达式 目 录 /* Example 2-1 CW02-01.C Calculate area of a circle.*/ #include <stdio.h> #define PI 3.14 void main() { float r, area; scanf("%f",&r); area = PI*r*r; printf("area=%f",area); } 1 3.140000 area r
INTEGER VARIABLES AND CONSTANTS 整教的类型和大 Integer Types and sizes 口在微机中,不同类型的整型数据在内存中占的字节数如下表: 类型名称 类型说明符 字节数 数值范围 基本整型 signed int 2 -32768~32767 短整型 signed] short [int] -32768~32764 长整型 signed] long [int] 4 2147483648~2147483647 无符号基本整型 unsigned [int 0~65535 无符号短整型 unsigned short [int] 2 0~65535 无符号长整型 unsigned long [int 4 0~4294967295 第二讲擲粪型、算莓和表达丸「
整数的类型和大小 Integer Types and Sizes 在微机中,不同类型的整型数据在内存中占的字节数如下表: inTeger VariaBLes anD ConsTanTs 第二讲 数据类型、运算符和表达式 目 录 类型名称 类型说明符 字节数 数值范围 基本整型 [signed] int 2 -32768~32767 短整型 [signed] short [int] 2 -32768~32767 长整型 [signed] long [int] 4 -2147483648~ 2147483647 无符号基本整型 unsigned [int] 2 0~65535 无符号短整型 unsigned short [int] 2 0~65535 无符号长整型 unsigned long [int] 4 0~4294967295