# sizeof operator

< cpp‎ | language

C++
 Language Standard Library Headers Freestanding and hosted implementations Named requirements Language support library Concepts library (C++20) Diagnostics library Utilities library Strings library Containers library Iterators library Ranges library (C++20) Algorithms library Numerics library Input/output library Localizations library Regular expressions library (C++11) Atomic operations library (C++11) Thread support library (C++11) Filesystem library (C++17) Technical Specifications

C++ language
General topics
Flow control
Conditional execution statements
Iteration statements (loops)
 for range-for (C++11)
Jump statements
Functions
Function declaration
Lambda function declaration
inline specifier
Exception specifications (until C++20)
noexcept specifier (C++11)
Exceptions
Namespaces
Types
Specifiers
 decltype (C++11) auto (C++11) alignas (C++11)
Storage duration specifiers
Initialization
Expressions
Alternative representations
Literals
Boolean - Integer - Floating-point
Character - String - nullptr (C++11)
User-defined (C++11)
Utilities
Attributes (C++11)
Types
typedef declaration
Type alias declaration (C++11)
Casts
Implicit conversions - Explicit conversions
static_cast - dynamic_cast
const_cast - reinterpret_cast
Memory allocation
Classes
Class-specific function properties
 Virtual function override specifier (C++11) final specifier (C++11)
 explicit (C++11) static
Special member functions
 Default constructor Copy constructor Move constructor (C++11)
 Copy assignment Move assignment (C++11) Destructor
Templates
 Template specialization Parameter packs (C++11)
Miscellaneous

Expressions
 General value categories (lvalue, rvalue, xvalue) order of evaluation (sequence points) constant expressions unevaluated expressions primary expressions lambda-expression(C++11) Literals integer literals floating-point literals boolean literals character literals including escape sequences string literals null pointer literal(C++11) user-defined literal(C++11) Operators Assignment operators: a=b, a+=b, a-=b, a*=b, a/=b, a%=b, a&=b, a|=b, a^=b, a<<=b, a>>=b Increment and decrement: ++a, --a, a++, a-- Arithmetic operators: +a, -a, a+b, a-b, a*b, a/b, a%b, ~a, a&b, a|b, a^b, a<>b Logical operators: a||b, a&&b, !a Comparison operators: a==b, a!=b, ab, a<=b, a>=b, a<=>b(C++20) Member access operators: a[b], *a, &a, a->b, a.b, a->*b, a.*b Other operators: a(...), a,b, a?b:c Default comparisons(C++20) Alternative representations of operators Precedence and associativity Fold expression(C++17) new-expression delete-expression throw-expression alignof sizeof sizeof...(C++11) typeid noexcept(C++11) Operator overloading Conversions Implicit conversions const_cast static_cast reinterpret_cast dynamic_cast Explicit conversions (T)a, T(a) User-defined conversion

Queries size of the object or type.

Used when actual size of the object must be known.

## Contents

### Syntax

 sizeof( type ) (1) sizeof expression (2)

Both versions are constant expressions of type std::size_t.

### Explanation

1) Yields the size in bytes of the object representation of type.
2) Yields the size in bytes of the object representation of the type of expression, if that expression is evaluated.
{"ft_lang_label":"__label__en","ft_lang_prob":0.71689945,"math_prob":0.90057063,"size":2605,"snap":"2020-10-2020-16","text_gpt3_token_len":694,"char_repetition_ratio":0.19031142,"word_repetition_ratio":0.14132762,"special_character_ratio":0.32207292,"punctuation_ratio":0.1468254,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9531039,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-02-25T16:51:40Z\",\"WARC-Record-ID\":\"<urn:uuid:a4884d1a-113e-43bf-9395-fa521522f7af>\",\"Content-Length\":\"64136\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:49370026-11ad-406d-b249-75559ff2db71>\",\"WARC-Concurrent-To\":\"<urn:uuid:296f0d6b-44bc-4b33-9d8f-1ff328965e64>\",\"WARC-IP-Address\":\"141.85.160.17\",\"WARC-Target-URI\":\"http://cpp.arh.pub.ro/cpp/language/sizeof\",\"WARC-Payload-Digest\":\"sha1:QESQD7WDH5O2BXBOTHNVUU54JLWBWYKK\",\"WARC-Block-Digest\":\"sha1:6SYJJLR5GGI2XETRBMBTZAURAUON2KQW\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-10/CC-MAIN-2020-10_segments_1581875146123.78_warc_CC-MAIN-20200225141345-20200225171345-00421.warc.gz\"}"}