C语言中查看类型的大小(占几个byte)
/*
sizeof是C语言的内置运算符,以字节为单位给出指定类型的大小。 C99和C11
提供%zd转换说明匹配sizeof的返回类型[2]。 一些不支持C99和C11的编译器可用%u
或%lu代替%zd
*/
/* 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 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; }