Operators are special symbols which instruct the compiler to perform certain logical or mathematical manipulations. For example; + is an operator that represents addition.
The data items the operators act upon are called Operands. It is the part of an instruction set which specifies what data is to be operated or manipulated on, while at the same time representing the data itself. Operators are generally used with operands to solve some expressions.
#include< stdio.h> int main( ) { int a=10, b=5,c=20, result; result= a+c-b; /* The result will be calculated in result variable */ printf("The result will be %d", result); return 0; }
In the above code a, b, c and result are operands and =, + and - are operators.
Computer languages generally define a set of built-in operators, and sometimes allow users to define completely new operators using operator overloading or operator coercion or even add new intent or meanings to existing operators.
Different different operators require different numbers of operands; some require two or some three and some act upon only one operand.
On the basis of the number of operands, operators fall into three categories. These are:
All the C operators are given below:
Category and nature | Operators | Associativity |
---|---|---|
Unary operators | ( ), { }, [ ], ->, . , ++, --(postfix) | Left to right |
+, -, ++, --, (type), !, *, sizeof, & | Right to left | |
Arithmetic operators (Binary operator) | /, %, * | Left to right |
+, - | ||
Bitwise Shift operator (Binary Operators) | << (left shift) >> ( right shift) |
Left to Right |
Relational Operators (Binary) | < , >, <=, >= | Left to Right |
==, != | ||
Bitwise logical operator (Binary operators) | & (AND) | Left to Right |
| (OR) | ||
^ (XOR) | ||
Logical operator (Binary Operators) | && (logical AND) | Left to Right |
|| (logical OR) | ||
Conditional Operator (Ternary Operator) | ? : | Right to Left |
Assignment Operators (Binary operator) | =, +=, -=, *=, /=, &=, |=, ^=, <<=, >>= | Right to Left |
Comma | , | Left to Right |