![]() |
![]() |
|
|
![]() |
![]() |
HP C/HP-UX Reference Manual: Version A.06.05 > Chapter 5 Expressions
and Operators ![]() sizeof Operator |
|
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) */ For expressions, the parentheses are optional, so the following is legal: sizeof x By convention, however, the parentheses are usually included. The operand can also be a data type, in which case the result is the length in bytes of objects of that type: sizeof(char) /* 1 on all machines */ The parentheses are required if the operand is a data type.
In general, the sizeof operator is used to find the size of aggregate data objects such as arrays and structures. You can use the sizeof operator to obtain information about the sizes of objects in your C environment. The following prints the sizes of the basic data types: /* Program name is "sizeof_example". This program If you execute this program, you get the following output: TYPE SIZE |
![]() |
||
![]() |
![]() |
![]() |
|||||||||||||
|