“C语言的基本数据类型”的版本间的差异
跳到导航
跳到搜索
Jihongchang(讨论 | 贡献) |
Jihongchang(讨论 | 贡献) |
||
第15行: | 第15行: | ||
return 0; | return 0; | ||
} | } | ||
+ | </syntaxhighlight><syntaxhighlight lang="console"> | ||
+ | char size: 1 | ||
+ | short size: 2 | ||
+ | int size: 4 | ||
+ | long int size: 4 | ||
+ | long long size: 8 | ||
+ | float size: 4 | ||
+ | double size: 8 | ||
+ | long double size: 8 | ||
+ | bool size: 1 | ||
</syntaxhighlight> | </syntaxhighlight> |
2022年10月26日 (三) 10:15的版本
https://www.bilibili.com/video/BV1vR4y1H7MY?p=5
#include<stdio.h>
//sizeof 关键字 计算变量或数据类型所占的字节个数
int main()
{
printf("char size: %d \n", sizeof(char));
printf("short size: %d \n", sizeof(short));
printf("int size: %d \n", sizeof(int));
printf("long int size: %d \n", sizeof(long int));
printf("long long size: %d \n", sizeof(long long));
printf("float size: %d \n", sizeof(float));
printf("double size: %d \n", sizeof(double));
printf("long double size: %d \n", sizeof(long double));
printf("bool size: %d \n", sizeof(bool));
return 0;
}
char size: 1
short size: 2
int size: 4
long int size: 4
long long size: 8
float size: 4
double size: 8
long double size: 8
bool size: 1