sizeof operator in c

Sizeof Operator in C – A Practical Tutorial

Table of Contents
    Add a header to begin generating the table of contents

    Sizeof Operator in C

    In C programming, the unary operator sizeof() returns the size of its operand in bytes. The sizeof() operator is discussed in detail in this article, along with illustrative examples of code.

    Sizeof() is used extensively in the C programming language. It is a compile-time unary operator, which can be used to compute the size (in bytes) of any data type of its operands.

     

    The operand may be an actual type-specifier (such as char or ints) or any valid expression. The sizeof() operator returns the total memory allocated for a particular object in terms of bytes.

     

    The resultant type of the sizeof() operator is size_t. Sizeof() can be applied both for primitive data types (such as char, ints, floats, etc) including pointers and also for the compound data types (such as structures, unions, etc). The sizeof() operator can be used in two different cases depending upon the operand types.

    sizeof operator in c
    Fig 1 : Syntax and Examples

    Output

    Below URL is to download the PDF version of the article (sizeof_operator_in_c_tutorial.pdf), let us know what you think about this tutorial.

     

    Sizeof operator in C – A practical tutorial (Download PDF)

    Interesting Note

    According to the C99 standards, the sizeof() operator yields the size (in integer bytes) of its operand, which may be an expression or the parenthesized name of a type. If the type of the operand is a variable length array type, the operand is evaluated at run-time; otherwise, the operand is not evaluated and the result is an integer constant, during the compile time itself.

    Share this material with your friend:

    Leave a Comment