Introduction: In this article i
am going to explain the use of unary operator sizeof with example program in C Language.
Description: In previous articles i explained the programs How to check for vowel or consonant using switch case and Calculate sum,average and division of marks using else-if ladder and Get number of days in month and year using else if ladder and Find greatest of two numbers using conditional operator and Find greatest of three numbers using multiple if statement.
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."
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..