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_t (§ 3.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; // ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access