Sizeof expr sizeof The sizeof operator yields the number of bytes in t

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
5.3.3 Sizeof [expr.sizeof]
The sizeof operator yields the number of bytes in the object representation of its operand. The operand
1
is either an expression, which is not evaluated, or a parenthesized type-id. The sizeof operator shall not
be applied to an expression that has function or incomplete type, or to an enumeration type before all its
enumerators have been declared, or to the parenthesized name of such types, or to an lvalue that designates
a bit-field. sizeof(char), sizeof(signed char) and sizeof(unsigned char) are 1; the
result of sizeof applied to any other fundamental type (3.9.1) is implementation-defined. [Note: in par-
ticular, sizeof(bool) and sizeof(wchar_t) are implementation-defined.69) ] [Note: See 1.7 for
the definition of byte and 3.9 for the definition of object representation. ]
When applied to a reference or a reference type, the result is the size of the referenced type. When applied
2
to a class, the result is the number of bytes in an object of that class including any padding required for
placing objects of that type in an array. The size of a most derived class shall be greater than zero (1.8).
70)
The result of applying sizeof to a base class subobject is the size of the base class type. When applied
to an array, the result is the total number of bytes in the array. This implies that the size of an array of n
elements is n times the size of an element.
The sizeof operator can be applied to a pointer to a function, but shall not be applied directly to a func-
3
tion.
The lvalue-to-rvalue (4.1), array-to-pointer (4.2), and function-to-pointer (4.3) standard conversions are not
4
applied to the operand of sizeof.
Types shall not be defined in a sizeof expression.
5
The result is a constant of type size_t. [Note: size_t is defined in the standard header
6
<cstddef>(18.1). ]