Unary Operator Sizeof in C Language

The unary operator sizeof in C generates the size of a variable or datatype, measured in the number of char size storage units required for the type.

In simple it can be said, C provides a compile-time unary operator called sizeof that can be used to compute the size of any object.

The expressions of sizeof in C

sizeof object and sizeof(type name)

Result in an unsigned integer value equal to the size of the specified object or type in bytes.

Actually, the resultant integer is the number of bytes required to store an object of the type of its operand.

An object can be a variable or array or structure. An array and structure are data structures provided in C.

A type name can be the name of any basic type like int or double or a derived type like a structure or a pointer.

For example,
sizeof(char) = 1bytes
sizeof(int) = 2 bytes

 

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: