描述
确定不同整型数据类型在内存中占多大(字节),输出不同整型数据类型在内存中占多大(字节)。
输入描述:
无
输出描述:
不同整型数据类型在内存中占多大(字节),具体格式详见输出样例,输出样例中的?为不同整型数据类型在内存中占的字节数。输出样例如下:
The size of short is ? bytes.
The size of int is ? bytes.
The size of long is ? bytes.
The size of long long is ? bytes.
在这题中我们总是会下意识的以为对于不同整数类型在内存中占多大字节在书中有,但真要我们写代码运算出来就两手抓黑。
在这题中其实只需要用到一个sizeof函数就可以运算出结果,结果如下图所示:
代码如下:
#include <stdio.h>
int main() {
printf("The size of short is %d bytes",sizeof(short));
printf("The size of int is %d bytes",sizeof(int));
printf("The size of long is %d bytes",sizeof(long));
printf("The size of long long is %d bytes",sizeof(long long));
}
希望我的这些可以给你带来帮助,请给位动动小手关注一下,谢谢