HPlogo HP C/HP-UX Reference Manual: Workstations and Servers > Chapter 5 Expressions

The sizeof Operator

» 

Technical documentation

Complete book in PDF

 » Table of Contents

 » Index

The sizeof operator is used to determine the size (in bytes) of a data object or a type.

Syntax

sizeof unary-expression
sizeof (type-name)

Description

The result of the sizeof operator is an unsigned int constant expression equal to the size of its operand in bytes. You can use the sizeof operator in two different ways. First, you can apply the sizeof operator to an expression. The result is the number of bytes required to store the data object resulting from the expression. Second, it may be followed by a type name inside parentheses. The result then is the number of bytes required to store the specified type.

In either usage, the sizeof operator is a compile-time operator that you can use in place of an integer constant.

The usual conversion of arrays of T to pointers to T is inhibited by the sizeof operator. The sizeof operator returns the number of bytes in an array rather than the number of bytes in a pointer.

When you apply the sizeof operator to an expression, the expression is not compiled into executable code. This means that side effects resulting from expression evaluation do not take place.