Friday, December 26, 2008

Operators-

1. Assignment operators-
The general form of this operator is
variable name=expression;
e.g. x=4;
Here the value 4 is assigned to the variable x. The variable can be assigned the value of other variable.
e.g. x=y;
Or x=x+1;
Type conversion-
We cannot convert integer to float or character to integer. For this type conversion is necessary.
It is assignment of a value to a variable of other datatype.
e.g. int x; char y;
x=(int)y;
Here in this example the value of y is converted to integer and then it is stored to x;

Multiple assignment-
In multiple assignment more than two assignments are done. Type conversion can be used.
e.g. int x,y,z;
x=y=z=4;
e.g.
void main()
{
Int x,y,z;
Char l;
Z=2
Y=5;
L=’a’;
X=z;
Printf(“%d%d%d”,x,y,z);
Y=x=z=0
Printf(“%d%d%d”,x,y,z);
X=(int)l;
Printf(“%d”,x);
Getch();
}
o/p-
first printf-252
second printf-000
third printf-97

2. Arithmetic operators-
The arithmetic operators are +,-,*,/. These are used for arithmetic operations.
e.g. int x,y,z;
x=y+z;
x=y-z;
x=y*z;
x=y/z;
y and z are initialized as per the need.

Increment and Decrement-
Increment- ++. This is used to increment the value of variable which has an initial value.
Decrement- --. This is used to decrement the value of variable which has an initial value.
X=0;
X++;
Y=1;
y--;
e.g.
void main()
{
Int x,y;
X=5;
Y=7;
Printf(“%d%d”,x.y);
X++;
y--;
Printf(“%d%d”,x.y);
Getch();
}
o/p-
first printf-57
second printf-65

3. Relational operators-
>- Greater than.
>=- Greater than or equal.
<- Less than.
<=- Less than or equal.
==- Equal.
!=- Not equal.
These relational operators are used in condition statements to check the conditions.
e.g. if(x > y)
if(x <= z)
if(x == y)
do
{
}while(y != 4);

4. Logical operators-
&&- And.
||- Or.
!- Not.
These operators work similarly as they are used in grammar.
e.g. if(x > y && y < z)
if(x < y || y > z)
if(!x < y && y < z)

No comments:

Watch tv!