What is the use of sizeof operator with example program in C Language

Introduction: In this article i am going to explain the use of unary operator sizeof  with example program in C Language.

The sizeof operator returns the number of bytes the operand (on which the operation is to be performed) occupies in memory i.e. the amount of space/storage, in bytes, required by the data type in memory. The Operand may be a variable, a constant or a data type qualifier.

Syntax:  sizeof (type name)
Here sizeof is unary operator and the type name is the operand.

Implementation: Let's create a program demonstrating the use of sizeof operator to check the number of bytes the various data type occupies

 #include<conio.h>
#include<stdio.h>
main()
{
   clrscr();
    printf("\nSize of character= %d byte",sizeof(char));
    printf("\nSize of short signed integer= %d bytes",sizeof(short signed int));
    printf("\nSize of short unsigned integer= %d bytes",sizeof(short unsigned int));
    printf("\nSize of long signed integer= %d bytes",sizeof(long signed int));
    printf("\nSize of long unsigned integer= %d bytes",sizeof(long unsigned int));
    printf("\nSize of float= %d bytes",sizeof(float));
    printf("\nSize of double= %d bytes",sizeof(double));
   getch();
}

Run the program by ctrl+F9

Output:

Size of character= 1 byte
Size of short signed integer= 2 bytes
Size of short unsigned integer= 2 bytes
Size of long signed integer= 4 bytes
Size of long unsigned integer= 4 bytes
Size of float= 4 bytes
Size of double= 8 bytes

Now over to you:
"If you like my work; you can appreciate by leaving your comments, hitting Facebook like button, following on Google+, Twitter, Linked in and Pinterest, stumbling my posts on stumble upon and subscribing for receiving free updates directly to your inbox . Stay tuned and stay connected for more technical updates."
Previous
Next Post »

If you have any question about any post, Feel free to ask.You can simply drop a comment below post or contact via Contact Us form. Your feedback and suggestions will be highly appreciated. Also try to leave comments from your account not from the anonymous account so that i can respond to you easily..