整数値の最大値、最小値 (C++)
C++
Published: 2019-12-07

やったこと

整数の最大値と最小値について確認してみます。

確認環境

$ g++ --version
g++ (Homebrew GCC 9.2.0) 9.2.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

調査

test.cpp

#include <bits/stdc++.h>
using namespace std;

int main() {
    printf("short int: %d ~ %d\n", SHRT_MIN, SHRT_MAX);
    printf("unsigned short int: 0 ~ %d\n", USHRT_MAX);
    printf("int: %d ~ %d\n", INT_MIN, INT_MAX);
    printf("unsigned int: 0 ~ %u\n", UINT_MAX);
    printf("long int: %ld ~ %ld\n", LONG_MIN, LONG_MAX);
    printf("unsigned long int: 0 ~ %lu\n", ULONG_MAX);
    printf("long long: %lld ~ %lld\n", LLONG_MIN, LLONG_MAX);
    printf("unsigned long long: 0 ~ %llu\n", ULLONG_MAX);
}

出力結果

short int: -32768 ~ 32767
unsigned short int: 0 ~ 65535
int: -2147483648 ~ 2147483647
unsigned int: 0 ~ 4294967295
long int: -9223372036854775808 ~ 9223372036854775807
unsigned long int: 0 ~ 18446744073709551615
long long: -9223372036854775808 ~ 9223372036854775807
unsigned long long: 0 ~ 18446744073709551615