An operator is a symbol that tells the Computer to perform certain mathematical or logical manipulations.

An expression is a sequence of operands and operators that reduces to single value.

Eg: 10+25 is an expression whose value is 35 C . operators can be classified into a no. of categories.

- Arithmetic
- Relational
- Logical
- Assignment
- Increment and Decrement
- Conditional
- Bitwise
- Special

C provides all the basic arithmetic operators, they are +, -, *, /, % Integer division truncates any fractional part. The modulo division produces the remainder of an integer division.

Example:

a + b a * b a / b

a - b -a * b a % b

Here "a"and "b" are variables and are known as operands. % cannot be used for floating point data. C does not have an operator for exponentiation.

When the operands in an expression are integers then the expression is an integer expression and the operation is called integer arithmetic. This always yields an integer value.

Floating Point Arithmetic involves only real operands of decimal or exponential notation. If x, y & z are floats, then

x = 6.0/7.0 = 0.857143

y = -1.0/3.0 = 0.333333

z = 3.0/2.0 = 1.500000

% cannot be used with real operands

These are the operators used to Compare arithmetic, logical and character expressions. the value of a relational express is either one or zero .it is 1 if one is the specified relation is true and zero if it is false.

Operator and Meaning

< is less than

< = is less than or equal to

> is greater than or equal to

> = is greater than or equal to

= = is equal to

! = is not equal to

illustrate the use of Logical Operators

void main ( ) { clrscr ( ); printf("In 5>3 && 5<10 : %3d", 5>3&&5<10); printf("In 8<5 || 5= =5 : % 3d", 8<5 || 5= =5); printf("In !(8 = =8) : %3d", !(8= =8) ; }

Logical Operators are used when we want to test more than one condition and make decisions. here the operands can be constants, variables and expressions Logical operators are &&, ||, !.

Logical or compound relational Expression name1 name2 name1&name2 name1||name2 name ! 1 1 1 1 0 1 1 0 0 1 1 0 0 1 0 1 0 1 0 0

Used to assign the result of an expression to a variable. â€ž= â€žis the assignment operator. In addition C has a set of â€žshort handâ€Ÿ assignment operators

Var Op = Exp :

Variable operator

shorthand assignment

Binary arithmetic operator

var op = exp; is equivalent to var = var op exp;

Example:

x + = 1; == > x = x+1

x+ = y+1 == > x = x+y+1

ShortHand Operator Assingment Operator a + = 1 a = a+1 a - = 1 a = a-1 a * = n+1 a = a* (n + 1) a / = n+1 a = a/(n+1) a % = b a = a % b

++ and - -

The Operator + + adds 1 to the operand while -- subtracts 1, Both are unary operators

Example : ++ x or x ++ == > x+=1 == > x=x+1 -- x or x- - == > x-=1 == > x=x-1

A Profix operator first adds 1 to the operand and then the result is assigned to the variable on left. A postfix operator first assigns the value to the variable on the left and the increments the operand.

it is used to check a condition and Select a Value depending on the Value of the condition.

Variable = (condition)? Value 1 : Value 2:

If the Value of the condition is true then Value 1 is e valued assigned to the varable, otherwise Value2.

Example:

big = (a>b)? a:b;

This exxp is equal to if (a>b) big = a;

else

big = b;

are used to perform operations at binary level i. e. bitwise. these operators are used for testing the bits, or Shifting them right or left . These operators are not applicable to float or double. Following are the Bitwise operators with their meanings.

Operator Meaning & Bitwise AND | Bitwise OR ^ Bitwise Exclusive â€“ OR << Left Shift >> Right Shift ~ Complement

News Walls