Knowledge Base
Home C

sizeof Operator

Category: C | Comments (0)

What is sizeof operator?


sizeof will return the number of bytes reserved for a variable or data type. The sizeof operator is a compile-time operator that returns an integer value. In other words since sizeof is a compile time operator, when used in a expression, it does not get compiled into executable code in the expression.


Syntax of this operator is

sizeof (type-name)

For instance if one wants to know the length of a data type it can be obtained by using sizeof operator as follows:

main() { printf("%d n", sizeof(int)); }

This returns the size of integer which is generally 2.


Suppose we have a program like below

main() { int a; float b=4.0 a= sizeof(10) / sizeof(b); )

Then the result would be sizeof integer value generally would be 2 and sizeof float which would be generally 4. Therefore result would be 2/4 which gives result as 0.


Next: typecasting in C




Post Comment


Members Please Login

Name:


Email:
 
(Optional. Used for Notification)

Title:

 
Comment:


Validation Code:
 <=>  (Enter this code in text box)
Subscribe





Google Sponsored Links

 

Daily Email Updates

Get Latest Knowledge Base Updates delivered directly to your Inbox...

Enter your email address:

Latest Knowledge Base Updates
 

C Tutorials

 

Related Tutorials