Introduction to operators in C programming

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.

operators and operands in C Programming,

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:

  1. Unary operators
  2. Binary operators
  3. Ternary operators
  • Whenever an operator uses a single operand to produce a new value, such operators are called unary operators and those operators will be unary by nature.
  • When an operator uses two operands to produce some value, such operators are called binary operators and those operators will be binary by nature. C language include a large number of operators in binary categories:
    1. Arithmetic Operators
    2. Bitwise Operators
    3. Logical Operators
    4. Relational Operators
    5. Assignment Operators
  • Whenever an operator uses three operands to produce some value, such operators are called ternary operators. In C language, there is only one ternary operator which is also known as conditional operator.

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