当前系统指定的类型大小
/*typesize.c -- 打印类型大小*/
#include<stdio.h>
int main(void){
/*C99为类型大小提供的%zd转换说明*/
printf("Type int has a size of %zd bytes.\n",sizeof(int) );
printf("Type char has a sizeof %zd bytes.\n",sizeof(char) );
printf("Type long has a sizeof %zd bytes.\n",sizeof(long) );
printf("Type long long has a sizeof %zd bytes.\n",sizeof(long long) );
printf("Type double has a sizeof %zd bytes.\n",sizeof(double) );
printf("Type long double has a sizeof %zd bytes.\n",sizeof(long double) );
return 0;
}
sizeof 为c语言内置运算符,以字节为单位给出指定类型的大小。C99和C11提供的%zd转换说明匹配sizeof的返回类型,一些不支持的可用%u和%lu替代。
网友评论