1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| #include <stdio.h> #include <stdint.h> #include <limits.h> #include <float.h>
int main(void) { printf("=== C语言数据类型详解 ===\n\n"); printf("整数类型:\n"); printf("char: %zu字节, 范围: %d 到 %d\n", sizeof(char), CHAR_MIN, CHAR_MAX); printf("short: %zu字节, 范围: %d 到 %d\n", sizeof(short), SHRT_MIN, SHRT_MAX); printf("int: %zu字节, 范围: %d 到 %d\n", sizeof(int), INT_MIN, INT_MAX); printf("long: %zu字节, 范围: %ld 到 %ld\n", sizeof(long), LONG_MIN, LONG_MAX); printf("long long: %zu字节, 范围: %lld 到 %lld\n", sizeof(long long), LLONG_MIN, LLONG_MAX); printf("\n无符号整数类型:\n"); printf("unsigned char: %zu字节, 最大值: %u\n", sizeof(unsigned char), UCHAR_MAX); printf("unsigned short: %zu字节, 最大值: %u\n", sizeof(unsigned short), USHRT_MAX); printf("unsigned int: %zu字节, 最大值: %u\n", sizeof(unsigned int), UINT_MAX); printf("unsigned long: %zu字节, 最大值: %lu\n", sizeof(unsigned long), ULONG_MAX); printf("unsigned long long: %zu字节, 最大值: %llu\n", sizeof(unsigned long long), ULLONG_MAX); printf("\n浮点数类型:\n"); printf("float: %zu字节, 精度: %d位, 范围: %e 到 %e\n", sizeof(float), FLT_DIG, FLT_MIN, FLT_MAX); printf("double: %zu字节, 精度: %d位, 范围: %e 到 %e\n", sizeof(double), DBL_DIG, DBL_MIN, DBL_MAX); printf("long double: %zu字节, 精度: %d位, 范围: %Le 到 %Le\n", sizeof(long double), LDBL_DIG, LDBL_MIN, LDBL_MAX); printf("\nC99固定宽度整数类型:\n"); printf("int8_t: %zu字节\n", sizeof(int8_t)); printf("int16_t: %zu字节\n", sizeof(int16_t)); printf("int32_t: %zu字节\n", sizeof(int32_t)); printf("int64_t: %zu字节\n", sizeof(int64_t)); return 0; }
|