Sizeof Operator
Prefix unary operator sizeof returns an integer constant that gives the size in
bytes of how much memory space is used by its operand (determined by its type,
with some exceptions).
Operator
sizeof can take either a type identifier or an unary expression as an
operand. You cannot use
sizeof with expressions of function type, incomplete
types, parenthesized names of such types, or with an lvalue that designates a bit
field object.
Sizeof Applied to Expression
If applied to expression, size of the operand is determined without evaluating the
expression (and therefore without side effects). Result of the operation will be the
size of the type of the expression’s result.
Sizeof Applied to Type
If applied to a type identifier,
sizeof returns the size of the specified type. Unit
for type size is the sizeof(char) which is equivalent to one byte. Operation
sizeof(char) gives the result 1, whether the char is signed or unsigned.
sizeof(char)
/* returns 1 */
sizeof(int)
/* returns 2 */
sizeof(unsigned long)
/* returns 4 */
When the operand is a non-parameter of array type, the result is the total number
of bytes in the array (in other words, an array name is not converted to a pointer
type):
int i, j, a[10];
//...
j = sizeof(a[1]);
/* j = sizeof(int) = 2 */
i = sizeof(a);
/* i = 10*sizeof(int) = 20 */
If the operand is a parameter declared as array type or function type, sizeof
gives the size of the pointer. When applied to structures and unions, sizeof gives
the total number of bytes, including any padding. Operator
sizeof cannot be
applied to a function.
mikroC
- C Compiler for Microchip PIC microcontrollers
mikroC
making it simple...
11 2
MikroElektronika:
Development
tools
-
Books
-
Compilers
page