sizeof is a unary compile-time operator that returns the length, in bytes, of the variable or
parenthesized type specifier that it precedes. For example, assuming that integers are 4 bytes and
doubles are 8 bytes, this fragment will display 8 4.
double f;
printf("%d ", sizeof f);
printf(''%d", sizeof(int));
Remember, to compute the size of a type, you must enclose the type name in parentheses. This is not
necessary for variable names, although there is no harm done if you do so.
C defines (using typedef) a special type called size_t, which corresponds loosely to an unsigned
integer. Technically, the value returned by sizeof is of type size_t .
Tuesday, September 2, 2008
The Compile-Time Operator sizeof
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment