sizeof

The number of bits of type char is specified by the preprocessor macro CHAR_BIT, defined in the standard include file limits.h.

The size of the block allocated is equal to the number of bytes for a single object of type int multiplied by 10, providing space for ten integers.

In addition, it is frequently difficult to predict the sizes of compound datatypes such as a struct or union, due to padding.

An equivalent syntax for allocating the same array space results from using the dereferenced form of the pointer to the storage address, this time applying the operator to a pointer variable: The operator sizeof produces the required memory storage space of its operand when the code is compiled.

The operand is written following the keyword sizeof and may be the symbol of a storage space, e.g., a variable, an expression, or a type name.

C++11 introduced the possibility to apply the sizeof parameter to specific members of a class without the necessity to instantiate the object to achieve this.

C++11 introduced variadic templates; the keyword sizeof followed by ellipsis returns the number of elements in a parameter pack.

When applied to a fixed-length datatype or variable, expressions with the operator sizeof are evaluated during program compilation; they are replaced by constant result-values.

The C99 standard introduced variable-length arrays (VLAs), which required evaluation for such expressions during program execution.

When calculating the size of any object type, the compiler must take into account any required data structure alignment to meet efficiency or architectural constraints.

Many computer architectures do not support multiple-byte access starting at any byte address that is not a multiple of the word size, and even when the architecture allows it, usually the processor can fetch a word-aligned object faster than it can fetch an object that straddles multiple words in memory.