*** Welcome to piglix ***

Sizeof


In the programming languages C and C++, the unary operator sizeof generates the size of a variable or datatype, measured in the number of char size storage units required for the type. As such, the construct sizeof (char) is guaranteed to be 1. The actual number of bits of type char is specified by the preprocessor macro CHAR_BIT, defined in the include file limits.h. On most modern systems this is eight bits. The result has an unsigned integral type that is usually denoted by size_t.

The operator is written preceding its operand, and may be applied either to a variable or any data type specification, including primitive types such as integer and floating-point types, pointer types, or compound datatypes (unions, structs, or C++ classes). When applied to a data type the type must be enclosed in parenthesis.

Many programs must know the storage size of a particular datatype. Though for any given implementation of C or C++ the size of a particular datatype is constant, the sizes of even primitive types in C and C++ may be defined differently for different platforms of implementation. For example, runtime allocation of array space may use the following code:

In this example, malloc allocates memory and returns a pointer to the memory block. The size of the block allocated is equal to the number of bytes for a single object of type int multiplied by 10, providing space for ten integers.


...
Wikipedia

...