HP C A.06.05 Reference Manual
Expressions and Operators
sizeof Operator
Chapter 5 131
sizeof Operator
Syntax
sizeof
exp
;
sizeof (
type_name
)
Arguments
exp
An expression of any type except function, void, or bit field.
type_name
The name of a predefined or user-defined data type, or the name of some
variable. An example of a predefined data type is int. A user-defined data
type could be the tag name of a structure.
Description
The sizeof unary operator finds the size of an object. It accepts two types of operands: an
expression or a data type. If the type of the operand is a variable length array, the operand is
evaluated - the compiler only determines what type the result would be for the expression
operand. Any side effects in the expression, therefore, will not have an effect. The result type
of the sizeof operator is size_t.
If the operand is an expression, sizeof returns the number of bytes that the result occupies
in memory:
/* Returns the size of an int (4 if ints are four bytes long) */
sizeof(3 + 5)
/* Returns the size of a double (8 if doubles are
* eight bytes long)
*/
sizeof(3.0 + 5)
/* Returns the size of a float (4 if floats are
* four bytes long)
*/
float x;
sizeof(x)
For expressions, the parentheses are optional, so the following is legal: