2

C语言的基本数据类型及其打印输出

 1 year ago
source link: https://blog.51cto.com/Qiue/5409418
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

C语言的基本数据类型及其打印输出

原创

Qiue. 2022-06-22 21:06:25 博主文章分类:C语言学习 ©著作权

文章标签 整型 浮点型 字符型 C语言 新手 文章分类 C/C++ 编程语言 yyds干货盘点 阅读数167

根据数据的类型,C语言大致将其分为三大类,分别为整数类型,小数类型,以及字符类型。整数类型用来打印整数,如123,625,1...这样的数。小数类型则用来打印小数,如1.25,263.12...这样的数。而字符类型则用来打印字母,如A,B,C,a,b,c...这样的数。下面将依次介绍这三大类的具体表示,及如何打印输出。

1.整数类型介绍及其打印输出。

1)整数类型介绍

其中最常用到的整数类型为 int 。

short

4或8字节

long long

2)整数类型的打印输出

short --- %hd ; int --- %d ; long --- %ld ; long long --- %lld ;

#include<stdio.h>

int main(void) {
short a = 0;
int b = 0;
long c = 0;
long long d = 0;
printf("a = %hd\n", a);
printf("b = %d\n", b);
printf("c = %ld\n", c);
printf("d = %lld\n", d);

return 0;
}

3)打印结果显示

C语言的基本数据类型及其打印输出_浮点型

2.小数类型介绍及其打印输出

1)小数类型介绍

float

单精度浮点型

double

双精度浮点型

2)小数类型打印输出

float --- %f ; double --- %lf ;

由于C语言系统默认小数为double类型,而float类型的表示范围比double类型要小。所以一般会在float类型的数后面加上‘f’防止编译器报警告。

#include<stdio.h>

int main(void) {
float a = 1.23f;
double b = 2.36;
printf("a = %f\n", a);
printf(" = %lf\n", b);

return 0;
}

3)打印结果显示

C语言的基本数据类型及其打印输出_新手_02

3.字符型介绍及其打印输出

1)字符型介绍

2)字符型打印输出

char --- %c ;

#include<stdio.h>

int main(void) {

char ch = 'a';
printf("ch = %c\n", ch);

return 0;
}

3)打印结果显示

C语言的基本数据类型及其打印输出_整型_03

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK