TheDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
sizeof operator is a built-in unary operator that yields the size, in bytes, of its operand. In C, a “byte” is strictly defined as the amount of memory required to store a single char object, guaranteeing that sizeof(char) always evaluates to 1.
Syntax
The operator accepts two types of operands: a parenthesized type name or an expression.sizeof(int)). When the operand is an expression, parentheses are syntactically optional but commonly used for precedence clarity.
Return Type
The result of asizeof operation is an unsigned integer type defined as size_t. This type is implementation-defined but guaranteed to be large enough to represent the size of the largest possible object on the target architecture. It is declared in the <stddef.h> header.
Evaluation Semantics
Compile-Time Evaluation For all standard data types, pointers, structures, and fixed-size arrays,sizeof is evaluated entirely at compile time. It is treated as an integer constant expression and does not incur runtime overhead.
Unevaluated Context
When the operand is an expression of a non-Variable Length Array type, the compiler determines the size based solely on the type of the expression’s result. The expression itself is placed in an unevaluated context. Consequently, no side effects within the expression are executed.
sizeof operator is evaluated at runtime.
Crucially, the C standard dictates that if the operand has a VLA type, the operand itself is evaluated. This means any side effects present within the operand expression will execute. If the operand is a VLA type-name, the size expression within the brackets is evaluated. However, applying sizeof to an already-declared VLA variable evaluates the variable itself, but does not re-evaluate the size expression from its original declaration.
Structural Padding and Alignment
When applied to aggregate types (struct or union), the value returned by sizeof includes the total memory footprint of the object. This encompasses all members as well as any internal or trailing padding bytes inserted by the compiler to satisfy architecture-specific memory alignment requirements.
Operand Constraints
Thesizeof operator violates compilation constraints if applied to the following:
- Incomplete types: Types lacking a complete definition, such as
voidor forward-declared structures without a defined body. - Function types: While you can evaluate the size of a pointer to a function, you cannot evaluate the size of a function itself.
- Bit-fields: It is illegal to apply
sizeofdirectly to a struct member defined as a bit-field, as bit-fields are not guaranteed to occupy standard byte boundaries.
Master C with Deep Grasping Methodology!Learn More





