sizeof operator
提供:cppreference.com
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
オブジェクトまたは型のクエリサイズ
Original:
Queries size of the object or type
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
オブジェクトの実際のサイズを知らなければならないときに使用します
Original:
Used when actual size of the object must be known
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
目次 |
[編集] 構文
sizeof( type )
|
|||||||||
sizeof expression None
|
|||||||||
両方のバージョンは、タイプstd::size_tの定数を返す.
Original:
Both versions return a constant of type std::size_t.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[編集] 説明
1)typeのオブジェクト表現のバイト数で返しますサイズ.
2) Original:
returns size in bytes of the object representation of type.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
評価された場合に、expressionによって返される型のオブジェクト表現のバイト数で返しますサイズ.
Original:
returns size in bytes of the object representation of the type, that would be returned by expression, if evaluated.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[編集] ノート
sizeof(char)、sizeof(signed char)、sizeof(unsigned char)とは関係なく、常に1の値に戻すCHAR_BIT.
Original:
sizeof(char), sizeof(signed char), and sizeof(unsigned char) always return 1, regardless of the value of CHAR_BIT.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
sizeofは関数型、不完全型、またはビットフィールドの左辺で使用することはできません.
Original:
sizeof cannot be used with function types, incomplete types, or bit-field lvalues.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
参照型に適用すると、結果は参照されている型のサイズです.
Original:
When applied to a reference type, the result is the size of the referenced type.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
クラスタイプに適用された場合、結果はそのクラスのオブジェクトのサイズと配列にそのようなオブジェクトを配置するために必要な追加のパディングです.
Original:
When applied to a class type, the result is the size of an object of that class plus any additional padding required to place such object in an array.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
空のクラスタイプに適用された場合は、常に1を返します。.
Original:
When applied to an empty class type, always returns 1.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[編集] キーワード
[編集] 例
出力例では、64ビット·ポインタと32ビットのintを使用してシステムに対応しています.
Original:
The example output corresponds to a system with 64-bit pointers and 32-bit int.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
#include <iostream> struct Empty {}; struct Bit {unsigned bit:1; }; int main() { Empty e; Bit b; std::cout << "size of empty class: " << sizeof e << '\n' << "size of pointer : " << sizeof &e << '\n' // << "size of function: " << sizeof(void()) << '\n' // compile error // << "size of incomplete type: " << sizeof(int[]) << '\n' // compile error // << "size of bit field: " << sizeof b.bit << '\n' // compile error << "size of array of 10 int: " << sizeof(int[10]) << '\n'; }
Output:
size of empty class: 1 size of pointer : 8 size of array of 10 int: 40