计算机对浮点类型的运算不精确。
#include <stdio.h>
int main() {
float a = 3.1;//单精度。使用4个字节32位
double b = 3.1;//双精度。8字节64位
long double c = 3.1;//长双精度。16字节128位
printf("a=%f b=%f c=%Lf ",a,b,c); return 0;
}
字符型数据
#include <stdio.h>
int main() {
printf("hello\nworld\n");//\n为换行符
printf("hello\rworld\n");//回车符\r,把指针移动到最开始的位置输出,及输出world。
printf("hello\bworld\n");//退格符\b,会将前一个字符去掉,及把o去掉了。
printf("hello\tworld\nhaha\tbupy");//制表符\t,相当于键盘上的tab键。
printf("hello\fworld\n");//换页符-------'\'为转义字符 printf("\\");//写2个'\\'即可正常输出一个\。
printf("\"jikexueyuan\"\n"); printf("\'jikexueyuan\'\n"); char ch = 'a';//声明字符需要用''。
printf("%c\n",ch);//26个字母大小写的编码查了32.
return 0;
}
运行结果:

其中char类型可以声明字符占用1个字节,32位。
当printf("%d\n",ch);用%d表示是输出的为编码,当用%c表示这输出字母。相同的字母大小写直接相差了32。如下图
#include <stdio.h>
int main() {
char ch = 'a';//声明字符需要用''。
char cha = 'A'; printf("ch=%d\ncha=%d\n",ch,cha);//26个字母大小写的编码查了32.
return 0;
}
运行结果:
