`sizeof` — C++ Keyword
`sizeof` — C++ Keyword
The sizeof keyword in C++: yields the size in bytes of a type or expression.
`sizeof` — C++ Keyword
The sizeof keyword in C++: yields the size in bytes of a type or expression.
Use reference pages to confirm names, categories, nearby facilities, and the constraints that matter before writing or reviewing code.
sizeofA compile-time operator that yields the size in bytes (as std::size_t) of a type or expression. The expression operand is not evaluated.
sizeof(type)
sizeof expression
sizeof...(pack) // C++11 parameter pack size
#include <print>
#include <cstddef>
struct Point { float x, y; };
int main() {
std::println("{}", sizeof(int)); // typically 4
std::println("{}", sizeof(double)); // typically 8
std::println("{}", sizeof(Point)); // 8 (2 × float)
int arr[10];
std::println("{}", sizeof arr); // 40 (10 × 4)
std::println("{}", sizeof arr / sizeof arr[0]); // 10 (element count)
// Expression is unevaluated
int x = 0;
std::println("{}", sizeof(x++)); // 4 – x is NOT incremented
std::println("{}", x); // 0
}
sizeof is resolved at compile time (except for VLAs in C99/C11).sizeof arr / sizeof arr[0] is the idiomatic element count; prefer std::size(arr) (C++17) or std::array.sizeof(void) is ill-formed in C++.sizeofint main() {
// Pick one facility from this reference page.
// Write the smallest program that exercises its main precondition,
// complexity rule, or lifetime constraint before scaling up.
return 0;
}