Q

Emertxe-News & Blog

Home » Blog » Sizeof operator in C – A practical tutorial
Sizeof operator in C – A practical tutorial
sizeof operator in C

sizeof operator in C – Usage

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.

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.

About the author: 

The author is a member of the embedded software team at Emertxe Information Technology (P) Ltd (http://www.emertxe.com). His areas of interest are embedded C programming combined with data structures and micro-controllers. He can be reached at [email protected]

YOU MAY ALSO LIKE

Our Training Programs for Freshers

Our Training Programs for Freshers

Introduction: Emertxe is the leading training institute in Bangalore for Embedded Systems and IoT domains. It is a pioneer in training freshers since 2003 by providing excellent placement opportunities for freshers. Over the years 70000+ students have made their...

Difference between typedef and macro in C

Difference between typedef and macro in C

Introduction In any programming language, there are a set of keywords available, which can’t be used as variable name. It is because keywords are reserved and they have a special meaning. Keywords which are also called as reserved names can be anything like a command...

Emertxe and ESSCI launch Virtual Internships for Engineering students

Emertxe and ESSCI launch Virtual Internships for Engineering students

Emertxe, India’s premier embedded systems engineering finishing school, has provided more than 650+ students placements in 2019-20 alone. During 2020, amidst challenging pandemic times it continues to support students with placement opportunities and new programs via...

1 Comment

  1. Irfan

    Most common question on data types is based on its size thank you so much for sharing this type of blog

    Reply

Submit a Comment

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