我是靠谱客的博主 愉快菠萝,这篇文章主要介绍C语言:计算 int, float, double 和 char 字节大小,现在分享给大家,希望可以做个参考。

#题目:使用 sizeof 操作符计算int, float, double 和 char四种变量字节大小。
sizeof 是 C 语言的一种单目操作符,如C语言的其他操作符++、–等,它并不是函数。
sizeof 操作符以字节形式给出了其操作数的存储大小。

代码:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <stdio.h> int main() { int integerType; float floatType; double doubleType; char charType; // sizeof 操作符用于计算变量的字节大小 printf("Size of int: %ld bytesn",sizeof(integerType)); printf("Size of float: %ld bytesn",sizeof(floatType)); printf("Size of double: %ld bytesn",sizeof(doubleType)); printf("Size of char: %ld byten",sizeof(charType)); return 0; }

运行结果:

复制代码
1
2
3
4
5
Size of int: 4 bytes Size of float: 4 bytes Size of double: 8 bytes Size of char: 1 byte

最后

以上就是愉快菠萝最近收集整理的关于C语言:计算 int, float, double 和 char 字节大小的全部内容,更多相关C语言:计算内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(80)

评论列表共有 0 条评论

立即
投稿
返回
顶部