- An operator is a special symbol that tells the compiler to perform some task.
- C- Language provides large number of In-build operators.
- An operator operates on operands.
- Operators can be dividing into the following categories:
- Arithmetic operators are used to perform Arithmetic calculation such as addition, subtraction multiplication and division
- Arithmetic operator are +,-,*,/.
- An assignment operator is used to assign value of right hand side expression to the left hand side expression. Example : a=10, b, b=a;
- Relational operators are used to perform some Relational task.
- They can be used for comparison purpose
- It helps to determine whether the given value is greater than, less than or equal to other value.
- Main operators are >,<,==,>=,<=.
- Logical operators are used to perform logical task.
- They can be used to combine multiple condition
- They helps to determine what conditions are true or false bused on the given criteria.
- Conditional operator is used to perform assignment based on given expression.
- It works similar to if….else statement.
- If given expression evaluates to true then the value of first expression is assigned otherwise value of second expression will be assigned to the left hand side identifier.
- Increment & Decrement operators Increment and Decrement operand’s value by 1.
- They are unary operator and works on single operand.
- They have two forms:
(1) Prefix notation:
- In prefix notation operator comes first before the operand. For example: ++i, -i
(2) Postfix notation:
- In postfix notation operator comes after the operand. For example i++,–i
- When prefix notation is used for assignment then the value will be either incremented or decremented first and then modified value will be assign to the left hand side operand.Example :inta,b=10; a=++b;
- When postfix notation is used then it will assign original value first and then after the value will be incremented and decremented.Example :inta,b=10; a=b++;
- Bitwise operators are used to perform operations on bit level.
- Main operators are &,:,^,>>,<<.
- We can also perform left shift and right shift operation at bit level.
- C-language provides the following special purpose operators:
(1) sizeof operator(2) member access operator(3)*,&
- size of operator returns the size of data variable passed within the argument.
- Member access operator (‘.’) and (‘->’) are used to access data member of a structure and union.
- *and & are used to define pointer variable and to assign address of variable
- A modulo operator (‘%’)is used to perform modulo operation.
- It returns reminder value of division operation. For example: n=n%2;