Sunday 20 May 2012

What are Operators? Describe six types of operator.


An Operator is a symbol that tells the computer to perform certain mathematical or logical manipulations. It is used to manipulate data and variables. They usually form a part of the mathematical or logical expressions e.g., y=a + b. here = and + are operators and y, a and b are operands.
Different types of operators are given bellow:
1.     Arithmetic operator
C provides all the basic arithmetic operators
Operators
Meaning
+
Addition or unary plus (single operand)
Subtraction or unary minus (single operand)
*
Multiplication
/
Division
%
Modulo division
When both the operands in a single arithmetic expression such as a + b are integers, the expression is called an integer expression, and the operation is called integer arithmetic.
If a and b are integers, then for a = 14 and b = 4 we have the following results:-
a – b = 10, a + b = 18, a * b = 56, a / b = 3 (decimal part truncated / quotient) and a % b = 2 (remainder of division)
2.     Relational operator
The symbols used to compare two quantities are called relative operators. It compare the operands and give its result is either true or false or one or zero.
There are six relational operators:
Operator
Meaning
< 
Is less than.
<=
Is less than or equal to.
> 
Is greater than.
>=
Is greater than or equal to.
==
Is equal to.
!=
Is not equal to.
For example, 10 < 20 is true but 20 < 10 is false. Among the six relational operators, each one is a complement of another operator.
> is complement of <=
< is complement of >=
== is complement of !=
3.     Logical operator
There are three logical operators, which are used to test more than one condition and make decisions. E.g. a > b && x = = 10
C has the following three logical operators
&&        meaning logical AND
¦¦             meaning logical OR
!             meaning logical NOT
Like the simple relational expression, a logical expression also yields a value of one or zero. The logical expression given above is true only if a > b is true and x == 10 is true. If either or both of them are false, the expression is false.
4.     Assignment operator
Assignment operators are used to assign the result of an expression to a variable. The usual assignment operator is ‘=’.
5.     Increment and decrement operator
C allows two very useful operators not generally found in other languages. These are the ++ (increment) and −− (decrement) operators.
The operator ++ adds 1 to the operand, while −− subtract 1. both are unary operators and taken the following form:
++a;  or  a++;  
−−a;  or a−−;
6.     Bitwise operator
Bitwise operators are used for manipulation of data at bit level. These operators are used for testing the bits, or shifted them right or left. These may not be applied to float or double.
Operator
Meaning
&
Bitwise AND
¦
Bitwise OR
^
Bitwise exclusive OR
<< 
Shift left
>> 
Shift right

No comments:

Post a Comment