Types of Operators in C language with examples

In C, operators are symbols that instruct the compiler to do an operation such as an arithmetic operation, logical operation, relational operation, bitwise operation, and so on. In programming languages such as C, C++, mathematical operators are used to accomplish these operations. The types of operators in C are arithmetic operators, relational operators, logical operators, bitwise operators and so on.

C Language provides a rich collection of operators. Here in this post we will see the operators supported in C-language, type of operators and precedence of operators



Operators in C

Operators use one or more operands to perform an action. Operators are symbols that inform to the computer to carry out operations with operands. The operations could be mathematical, logical or relational. C Language provides a rich set of operators.



Types of Operators in C

The Operators are categorized in the following on the basis of use.

  • Arithmetic operators
  • Relational operators
  • Logical operators
  • Unary operators
  • Conditional operator
  • Assignment operators
  • Bitwise operators
  • Other operators


Precedence of Operators in C

The Precedence of Operator determines order of the operators to be evaluated in an expression. Operations may be evaluated in two directions, left to right and right to left.

The table below illustrates the precedence of the operators and it’s direction of evaluation.

CategoryOperatorsDirections
Group( ) [ ] Left to right
Postfix -> . Left to right
Postfix ++ — Left to right
Unary+ – ! ~ Right to Left
Prefix++ —Right to Left
Unary (type)* sizeof Right to Left
Multiplicative * / % Left to right
Additive + – Left to right
Shift << >> Left to right
Relational < <= > >= Left to right
Equality == != Left to right
Bitwise AND& Left to right
Bitwise XOR^ Left to right
Bitwise OR| Left to right
Logical AND&& Left to right
Logical OR || Left to right
Conditional ?: Right to Left
Assignment = += -= *= /= %=>>= <<= &= ^= |= Right to Left
Comma , Left to right


Arithmetic Operators

The arithmetic operators are used to perform mathematical arithmetic operations such as addition, subtraction, multiplication, division and module.



Relational Operators

The relational operators are used to compare two operands. The relational operators will compare and return true or false. The relational operators are equal, not equal, greater than, greater than or equals to, less than, less than or equals to.



Logical Operators

The logical operators will perform the logical opeartions between the operands. The logical operators are AND, OR and NOT.



Assignment Operators

The assignment operators are used to assign a value or expression to a variable. The assignment operators are set the values to the variable. The assignment operators are =, +=, -=, *=, /=, %=,>>=, <<=, &=, ^=, |=



Conditional Operators

The conditional operator is used to check the condition before assigning the value. The conditional operators are called as ternary operators. The conditional operator is ?:



Bitwise Operators

The bitwise operators are used to perform the bitwise manipulations. The bitwise operators are Bitwise AND, bitwise OR, bitwise NOT and bitwise XOR.



Unary Operators

The unary operators are used with a single operand. The positive or negative values are used to specify with unary operators. The unary operators are +, -, (type)* sizeof.



Leave a Reply

Your email address will not be published. Required fields are marked *