4.9. The sizeof Operator

The sizeof operator returns the size, in bytes, of an expression or a type name. The operator is right associative. The result of sizeof is a constant expression (§ 2.4.4, p. 65) of type size_t3.5.2, p. 116). The operator takes one of two forms:

sizeof (type)sizeof expr

In the second form, sizeof returns the size of the type returned by the given expression. The sizeof operator is unusual in that it does not evaluate its operand:

Sales_data data, *p;sizeof(Sales_data); // size required to hold an object of type Sales_datasizeof data; // size of data's type, i.e., sizeof(Sales_data)sizeof p;    // size of a pointersizeof *p;   // size of the type to which p points, i.e., sizeof(Sales_data)sizeof data.revenue; // ...

Get C++ Primer, Fifth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.