Operator is a symbol or letter used to indicate a specific operation on variables in a program.
Operator act upon the data items called as operands.
Example: A+B ;
Here A and B are operand variable and + is operator , And the function of it to add the values stored in the variable A and B.
Rules for formation of an expression
- A signed or unsigned constant or variable is an expression.
- Two expression connected by an operator is also an expression .
- Two operator should not occur in continuation .
1. Arithmetic operators
2. Relational operators
3. Logical operators
4. Assignment operators
5. Unary operators
6. Conditional or Ternary operators
7. Bit-wise operators
8. Comma operators
Arithmetic operators are used to perform various arithmetic calculations like addition, subtraction, multiplication and division.
|%||Modulus or remainder||X%Y|
Program to demonstrate Arithmetic Operators .
int a, b, sum, sub, div, rem, mul;
printf(“enter value of a and b”);
printf(“addition is =%d”,sum);
printf(“subtraction is =%d”,sub);
printf(“multiplication is =%d”,mul);
printf(“remainder is =%d”,rem);
printf(“division is =%d”,div);
2 Relational operators
A Relational operator is used to compare two values of the operands and the result of such an operation is always logical .
Relational operator are used in decision making statements.
|>=||Greater than or equal to||x>=y|
|<=||Less then or equal to||X<=y|
|!=||Not equal to||X!=y|
3 Logical Operators
Logical operators are used to connect relational expressions or logical expressions.
The result of such operations is always logical mean either true or false.
4 Assignment operators
Assignment operator is an operator in which the variable on the left side of the equal sign is set equal to the value of the operand on the right side of the equal sign.
The most commonly used assignment operation is =.
Where identifier generally represents a variable and expression represents a constant.
Note : if the two operands in an assignment expression are of different data types, then the value on the right will be automatically converted to the type of the identifier on the left.
5 unary operators
Unary operator are the operators that act upon a single operand to produce a new value.
Unary operator usually precede their single operands.
|–||Unary minus||-7.5, -(x+y)|
|*||Value at address||*a|
|!||Not or negation||!a|
|sizeof||Size of data type||Int i ; sizeof(i)|
6 Conditional or Ternary Operators
Conditional operator (? : ) is the condensed from of an if then else statement of c.
The general from of conditional operator is :
exp 1 ? exp 2 :exp 3
where exp 1 , exp 2 and exp 3 are the expressions.
e.g z=(x > y ) ? X:y;
Int a, b, big;
printf(“\n enter two numbers”);
scanf(“%d%d”, &a, &b);
big=(a > b)? a:b;
printf(“the greater number =%d, big”);
Bitwise operators are the operators which operate at bit level and allows the user to manipulate individual bits.
Bitwise operator used in low level means machine level programming.
|<<||Left shift of bits|
|>>||Right shift of bits|