实型常量
表示形式:
十进制数形式:(必须有小数点) 如0.123, .123, 123.0, 0.0, 123.
指数形式:(e或E之前必须有数字;指数必须为整数)如12.3e3 ,123E2, 1.23e4 , e-5 , 1.2E-3.5
实型常量的类型
默认double型
在实型常量后加字母f或F,认为它是float 型
字符型常量
定义:用单引号括起来的单个普通字符或转义字符.
image.png
字符常量的值:该字符的ASCII码值
image.png
转义字符:反斜线后面跟一个字符或一个代码值表示
无标题.jpg
例 转义字符举例(ch2_001.c,ch2_004.c)
main()
{
printf("\101 \x42 C\n");
printf("I say:\"How are you?\"\n");
printf("\\C Program\\\n");
printf("Turbo \'C\'");
}
运行结果:(屏幕显示)
A B C
Isay:”How are you?”
\C Program\
Turbo ‘C’
字符串常量
定义:用双引号(“”)括起来的字符序列
存储:每个字符串尾自动加一个 ‘\0’ 作为字符串结束标志
例 字符串“hello”在内存中
image.png例 空串 “”
image.png字符常量与字符串常量不同
例: char ch;
ch=‘A’;
网友评论