CKTIS / C++
sizeof — size of a type or object in bytes
The sizeof operator returns a type's size in bytes as a constant of type std::size_t. Its expression operand is not evaluated, and an array retains its full size rather than being converted to a pointer.
Version: C++23; repository compiler flag, production runtime not attested
Syntax
sizeof unary-expression
sizeof(expression)
sizeof(type-id)sizeof returns the size of its operand's type in bytes as an integral constant expression of type std::size_t (declared in <cstddef>). Parentheses are required for a type: sizeof(int); an expression permits sizeof x or sizeof(x). sizeof(char) is always 1; do not assume fixed sizes for other types.
An expression operand is not evaluated: sizeof(i++) does not increment i. It must still be type-correct. Function types, incomplete types (including void), and expressions designating bit-fields are not allowed. For a reference type, the result is the size of the referenced type.
For an array, the result includes every element, without conversion to a pointer. Thus sizeof(values) / sizeof(values[0]) counts elements of an actual array, but is not an element counter for a pointer or a function parameter written as an array. Applying sizeof to a pointer measures the pointer itself, not the pointed-to storage.
A class's size includes padding; it need not equal the sum of its members' sizes. The separate operator sizeof...(pack) counts pack elements, not bytes. The example prints the element count and the unchanged i. The source is an evolving standard draft, not a frozen C++23 publication.
Examples
#include <cstddef>
#include <iostream>
int main() {
int values[3] = {10, 20, 30};
int i = 0;
constexpr std::size_t count = sizeof(values) / sizeof(values[0]);
static_assert(count == 3);
static_assert(sizeof(char) == 1);
(void)sizeof(i++);
std::cout << count << '\n' << i << '\n';
}
Result
3 0
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.