参考代码:
#include<stdio.h>
int main()
{
printf("The size of short is %d bytes.\n", sizeof(short));
printf("The size of int is %d bytes.\n", sizeof(int));
printf("The size of long is %d bytes.\n", sizeof(long));
printf("The size of long long is %d bytes.\n", sizeof(long long));
return 0;
}
答案解析: 这类入门的题目基本都是没有输入操作的。 本题的关键是要掌握C语言的 sizeof 这个操作符。 sizeof 是C语言的一个单目操作符,用来计算不同类型数据所占内存空间的大小,单位是字节。 这里多说一下常见类型的大小:
8比特位=1个字节 int 的大小是4个字节 char 是1个字节 short是2个字节 lon4g是个字节 long long是8个字节 float是4个字节 double是8个字节
注意:新手要注意换行问题,别忘了加\n。