名前空間
変種
操作

基本的な型

提供: cppreference.com
< cpp‎ | language


 
 
C++言語
一般的なトピック
フロー制御
条件付き実行文
繰り返し文 (ループ)
ジャンプ文
関数
関数宣言
ラムダ関数宣言
inline 指定子
例外指定 (非推奨)
noexcept 指定子 (C++11)
例外
名前空間
指定子
decltype (C++11)
auto (C++11)
alignas (C++11)
記憶域期間指定子
初期化
代替表現
リテラル
ブーリアン - 整数 - 浮動小数点
文字 - 文字列 - nullptr (C++11)
ユーザ定義 (C++11)
ユーティリティ
属性 (C++11)
typedef 宣言
型エイリアス宣言 (C++11)
キャスト
暗黙の変換 - 明示的な変換
static_cast - dynamic_cast
const_cast - reinterpret_cast
メモリ確保
クラス
クラス固有の関数特性
特別なメンバ関数
テンプレート
その他
 

(Also see the list of type-related utilities that are provided by C++.)

目次

[編集] Boolean 型

bool - type, capable of holding one of the two values: true or false.

[編集] 文字 型

signed char - 正負の文字表現のタイプ
unsigned char - 非負の文字表現のタイプ
char - type for character representation which can be most efficiently processed on the target system (equivalent to either signed char or unsigned char).
wchar_t - type for wide character representation
char16_t - type for UTF-16 character representation (C++11およびそれ以降)
char32_t - type for UTF-32 character representation (C++11およびそれ以降)

[編集] 整数型

int - basic integer type. Can be omitted if any of the modifiers are present. If no length modifiers are present, guaranteed to have width of at least 16 bits. However, on 32/64 bit systems it is almost exclusively guaranteed to have width of at least 32 bits (see below).

[編集] 修飾子

Modifies the integer type. Can be mixed in any order. Only one of each group can be present in type definition.

Signedness

signed - target type will have signed representation (this is the default if omitted)
unsigned - target type will have unsigned representation

サイズ

short - target type will be optimized for space and will have width of at least 16 bits.
long - target type will have width of at least 32 bits.
long long - target type will have width of at least 64 bits (C++11およびそれ以降)

[編集] 属性

The following table summarizes all available integer types and their properties:

Type specifier Equivalent type Width in bits by data model
C++ standard LP32 ILP32 LLP64 LP64
short
short int 16
以上
16 16 16 16
short int
signed short
signed short int
unsigned short
unsigned short int
unsigned short int
int
int 16
以上
16 32 32 32
signed
signed int
unsigned
unsigned int
unsigned int
long
long int 32
以上
32 32 32 64
long int
signed long
signed long int
unsigned long
unsigned long int
unsigned long int
long long
long long int
(C++11)
64
以上
64 64 64 64
long long int
signed long long
signed long long int
unsigned long long
unsigned long long int
(C++11)
unsigned long long int

Note: the C++ Standard guarantees that 1 == sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long) <= sizeof(long long).

[編集] データモデル

32ビットシステム:

  • LP32:
  • Win16 API
  • ILP32;
  • Win32 API
  • UnixとUnixらしいシステム (Linux, Mac OS X)

64ビットシステム:

  • LLP64
  • Win64 API
  • LP64
  • UnixとUnixらしいシステム (Linux, Mac OS X)

[編集] 浮動小数点型

float - 単精度浮動小数点型。通常は IEEE-754 32 ビット浮動小数点型である。
double - 倍精度浮動小数点型。通常は IEEE-754 64 ビット浮動小数点型である。
long double - extended precision floating point type. Does not necessarily map to types mandated by IEEE-754. Usually 80-bit x87 floating point type on x86 and x86-64 architectures.

[編集] 値の範囲

The following table provides a reference for limits of common numeric representations. Note, that all popular data models (including all of ILP32, LP32, LP64, LLP64) use two's complement arithmetic. Also, the C++ Standard does not specify which arithmetic would be used, thus it guarantees only the limits of one's complement arithmetic.

タイプ ビットでサイズ Format Value range
Approximate Exact
文字 8 正負 (一の補数) -127127
正負 (二の補数) -128 ~ 127
非負 0255
integral 16 正負 (一の補数) ± 3.27 · 104 -3276732767
正負 (二の補数) -3276832767
非負 06.55 · 104 065535
32 正負 (一の補数) ± 2.14 · 109 -2,147,483,6472,147,483,647
正負 (二の補数) -2,147,483,6482,147,483,647
非負 04.29 · 109 04,294,967,295
64 正負 (一の補数) ± 9.22 · 1018 -9,223,372,036,854,775,8079,223,372,036,854,775,807
正負 (二の補数) -9,223,372,036,854,775,8089,223,372,036,854,775,807
非負 01.84 · 1019 018,446,744,073,709,551,615
floating
point
32 IEEE-754 ± 3.4 · 10± 38
(~7 digits)
  • min subnormal: ± 1.401,298,4 · 10-47
  • min normal: ± 1.175,494,3 · 10-38
  • max: ± 3.402,823,4 · 1038
64 IEEE-754 ± 1.7 · 10± 308
(~15 digits)
  • min subnormal: ± 4.940,656,458,412 · 10-324
  • min normal: ± 2.225,073,858,507,201,4 · 10-308
  • max: ± 1.797,693,134,862,315,7 · 10308

[編集] キーワード

bool, true, false, char, wchar_t, char16_t, char32_t, int, short, long, signed, unsigned, float, double

[編集] 参考