0
点赞
收藏
分享

微信扫一扫

【C primer Plus】如何知道当前系统的指定类型的大小是多少?

# include<stdio.h>
int main()
{
// c99
printf("Type int has a size of %zd bytes.\n", sizeof(int));
printf("Type char has a size of %zd bytes.\n", sizeof(char));
printf("Type long has a size of %zd bytes.\n", sizeof(long));
printf("Type long long has a size of %zd bytes.\n", sizeof(long long));
printf("Type double has a size of %zd bytes.\n", sizeof(double));
printf("Type long double has a size of %zd bytes.\n", sizeof(long double));
return 0;
}
Type int has a size of 4 bytes.
Type char has a size of 1 bytes.
Type long has a size of 4 bytes.
Type long long has a size of 8 bytes.
Type double has a size of 8 bytes.
Type long double has a size of 16 bytes.
  • long 类型和 int 类型大小一样;
  • long long 类型和 double 类型大小一样;
  • 别忘了 long double 是 double 长度两倍;


举报

相关推荐

0 条评论