1.C语言中的数据类型
char //字符数据类型
short //短整型
int //整型
long //长整型
long long //更长的整型
float //浮点型(单精度)
double //浮点型(双精度)
- 用C语言所写出来的程序来解决生活中所遇到的问题。C语言所提供的这么多的数据类型,能够为使用者节省空间和提供丰富的选择性。
#include<stdio.h>
int main()
{
int age=20;
char ch='a';
short num=10;
float weight=58.6;
double d=0.0; //double的精度比float高
return 0;
}
2.C语言中的输出函数printf
#include<stdio.h>
int main()
{
printf("haha\n");
printf("hello\n");
printf("好好学习,天天向上\n");
printf("123456\n");
return 0;
}
用显示屏将数据显示出来
\n是转义字符,是将输出结果换行的作用
输出结果:
haha
hello
好好学习,天天向上
123456
3.如何用sizeof计算数据类型的大小
-
sizeof是关键字
(1).是C语言提供的,不能自己创建关键字
(2).变量名不能是关键字 -
作用是计算变量或者类型所占空间的大小
#include<stdio.h>
int main()
{
printf("%d\n",sizeof(char));
printf("%d\n",sizeof(short));
printf("%d\n",sizeof(int));
printf("%d\n",sizeof(long));
printf("%d\n",sizeof(long long));
printf("%d\n",sizeof(float));
printf("%d\n",sizeof(double));
return 0;
}
sizeof的单位是: byte-字节
输出结果:
1
2
4
4
8
4
8
4.计算机中的单位
- bit-比特位
- byte-字节=8bit
- KB=1024byte
- MB=1024KB
- GB=1024MB
- TB=1024GB
- PB=1024TB
- ……
各位家人们,点个赞支持一下呗