sizeof operator

From cppreference.com
< cpp‎ | language
 
 
 
 

Queries size of the object or type.

Used when actual size of the object must be known.

Syntax

sizeof( type ) (1)
sizeof expression (2)

Both versions return a constant of type std::size_t.

Explanation

1) Returns size in bytes of the object representation of type.
2) Returns size in bytes of the object representation of the type that would be returned by expression, if evaluated.

Notes

Depending on the computer architecture, a byte may consist of 8 or more bits, the exact number being recorded in CHAR_BIT.

sizeof(char), sizeof(signed char), and sizeof(unsigned char) always return 1.

sizeof cannot be used with function types, incomplete types, or bit-field glvalues.

When applied to a reference type, the result is the size of the referenced type.

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.

When applied to an empty class type, always returns 1.

When applied to an expression, sizeof does not evaluate the expression, and even if the expression designates a polymorphic object, the result is the size of the static type of the expression. Lvalue-to-rvalue, array-to-pointer, or function-to-pointer conversions are not performed. Temporary materialization, however, is (formally) performed for prvalue arguments: sizeof determines the size of the result object. (since C++17)

Keywords

sizeof