Special Operators
C language supports some special operators such as unary operator, comma operator, sizeof operator, pointer operators (& and *) and member selection operators (. and ->).
a) Unary minus operator: Unary minus (-) operator changes sign of the given operand. i.e., +ve sign is changed as –ve sign and –ve sign is changed as +ve sign.
Example: +10 → -10
-456 → +456
b) Comma Operator: Comma (,) operator is used to separate the operands from one to another.
Example: int x,y;
c) sizeof Operator: sizeof operator is a compile time operator used to return the number of bytes occupied by the given operand. The general format of sizeof operator is:
Syntax: sizeof(Operand);
Here,
The operand may be a variable, a constant or a data type.
/* EXAMPLE PROGRAM FOR SIZEOF OPERATOR */
#include<stdio.h>
#include<conio.h>
main()
{
int i;
char ch;
float f;
double d;
clrscr();
printf("\n THE SIZEOF CH VARIABLE :%d BYTES",sizeof(ch));
printf("\n THE SIZEOF I VARIABLE :%d BYTES",sizeof(i));
printf("\n THE SIZEOF F VARIABLE :%d BYTES",sizeof(f));
printf("\n THE SIZEOF D VARIABLE :%d BYTES",sizeof(d));
printf("\n THE SIZEOF CHAR DATA TYPE :%d BYTES",sizeof(char));
printf("\n THE SIZEOF INT DATA TYPE:%d BYTES",sizeof(int));
printf("\n THE SIZEOF FLOAT DATA TYPE :%d BYTES",sizeof(float));
printf("\n THE SIZEOF DOUBLE DATA TYPE :%d BYTES",sizeof(double));
printf("\n THE SIZEOF CHAR CONSTANT VALUE :%d BYTES",sizeof('@'));
printf("\n THE SIZEOF INT CONSTANT VALUE :%d BYTES",sizeof(225));
printf("\n THE SIZEOF FLOAT CONSTANT VALUE:%d BYTES",sizeof(23.45f));
printf("\n THE SIZEOF DOUBLE CONSTANT VALUE :%d BYTES",sizeof(456.678));
}
No comments:
Post a Comment