色々なデータ型の最大値、最小値のコピペ。自分の環境でIntとかがどれくらいの範囲の値を使えるのか知っておくのは大事だと思う。
#include <stdio.h> #include <limits.h> int main() { printf("char size: %d\n", CHAR_BIT); printf("char max: %d\n", CHAR_MAX); printf("char min: %d\n", CHAR_MIN); printf("int max: %d\n", INT_MAX); printf("int min: %d\n", INT_MIN); printf("long max: %ld\n", LONG_MAX); printf("long min: %ld\n", LONG_MIN); printf("long long max: %lld\n", LLONG_MAX); printf("long long min: %lld\n", LLONG_MIN); printf("singed char max: %d\n", SCHAR_MAX); printf("signed char min: %d\n", SCHAR_MIN); printf("short max: %d\n", SHRT_MAX); printf("short min: %d\n", SHRT_MIN); printf("unsigned char max: %d\n", UCHAR_MAX); printf("unsigned int max: %u\n", UINT_MAX); printf("unsigned long max: %lu\n", ULONG_MAX); printf("unsigned short max: %u\n", USHRT_MAX); printf("unsigned long long max: %llu\n", ULLONG_MAX); return 0; }
結果も同じで
char size: 8 char max: 127 char min: -128 int max: 2147483647 int min: -2147483648 long max: 9223372036854775807 long min: -9223372036854775808 long long max: 9223372036854775807 long long min: -9223372036854775808 singed char max: 127 signed char min: -128 short max: 32767 short min: -32768 unsigned char max: 255 unsigned int max: 4294967295 unsigned long max: 18446744073709551615 unsigned short max: 65535 unsigned long long max: 18446744073709551615
だった。