HP C A.06.05 Reference Manual

Expressions and Operators
sizeof Operator
Chapter 5132
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 */
sizeof(short) /* 2 on HP 9000 Series */
sizeof(float) /* 4 on HP 9000 Series */
sizeof(int *) /* 4 on HP 9000 Series */
The parentheses are required if the operand is a data type.
NOTE The results of most sizeof expressions are implementation dependent. The
only result that is guaranteed is the size of a char, which is always 1.
In general, the sizeof operator is used to find the size of aggregate data objects such as
arrays and structures.
Example
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
* demonstrates a few uses of the sizeof operator.
*/
#include <stdio.h>
int main(void)
{
printf("TYPE\t\tSIZE\n\n");
printf("char\t\t%d\n", sizeof(char));
printf("short\t\t%d\n", sizeof(short));
printf("int\t\t%d\n", sizeof(int));
printf("float\t\t%d\n", sizeof(float));
printf("double\t\t%d\n", sizeof(double));
}