C Operators

C Operators are symbols that take one or two operands, perform a specific action on these operands, and returns the result.

Operators can be classified into following groups.

  • C Assignment Operators
  • C Arithmetic Operators
  • C Logical Operators
  • C Relational Operators
  • C Bitwise Operators
  • C Ternary Operator

In this tutorial, we shall go through each of these Operators, and also list out individual tutorials that describe respective operators in detail.

Assignment Operators

Arithmetic operators are used to perform common operations like addition, subtraction, multiplication, division, etc.

The following table specifies symbol, example, and description for each of the Assignment Operator in C programming.

AssignmentOperation Operator Symbol Example Description
Simple Assignment = x = 2 Assign x with 2.
Addition Assignment += x += 3 Add 3 to the value of x and assign the result to x.
Subtraction Assignment -= x -= 3 Subtract 3 from x and assign the result to x.
Multiplication Assignment *= x *= 3 Multiply x with 3 and assign the result to x.
Division Assignment /= x /= 3 Divide x with 3 and assign the quotient to x.
Remainder Assignment %= x %= 3 Divide x with 3 and assign the remainder to x.
Bitwise AND Assignment &= x &= 3 Perform x & 3 and assign the result to x.
Bitwise OR Assignment |= x |= 3 Perform x | 3 and assign the result to x.
Bitwise-exclusive-OR Assignment ^= x ^= 3 Perform x ^ 3 and assign the result to x.
Left-shift Assignment <<= x <<= 3 Left-shift the value of x by 3 places and assign the result to x.
Right-shift Assignment >>= x >>= 3 Right-shift the value of x by 3 places and assign the result to x.

The following are the list of detailed tutorials for Arithmetic Operators.

  • C Simple Assignment Operator
  • C Addition Assignment Operator
  • C Subtraction Assignment Operator
  • C Multiplication Assignment Operator
  • C Division Assignment Operator
  • C Remainder Assignment Operator
  • C Bitwise AND Assignment Operator
  • C Bitwise OR Assignment Operator
  • C Bitwise XOR Assignment Operator
  • C Left-shift Assignment Operator
  • C Right-shift Assignment Operator

Arithmetic Operators

Arithmetic operators are used to perform common operations like addition, subtraction, multiplication, division, etc.

Arithmetic Operation Operator Symbol Example Description
Addition + a + b Returns sum of a and b.
Subtraction a – b Returns difference of b from a.
Multiplication * a * b Returns product of a and b.
Division / a / b Returns the quotient when a is divided by b.
Modular Division % a % b Returns reminder when a is divided by b.
Increment ++ a++ or ++a Increments the value of a by one.
Decrement a– or –a Decrements the value of a by one.

The following are the list of detailed tutorials for Arithmetic Operators.

Logical Operators

Logical operators are used to perform boolean operations like AND, OR, and NOT.

Logical Operation Operator Symbol Example Description
AND && x && y Returns AND between x and y.
OR || x || y Returns OR between x and y.
NOT ! !x Returns negation of x.

The following are the list of detailed tutorials for Logical Operators.

Relational Operators

Relational operators are used to compare given values. These are also called Comparison Operators.

Relational Operation Operator Symbol Example Description
Equal To == x == y Returns true if x is equal to y, else it returns false.
Not Equal != x != y Returns true if x is not equal to y, else it returns false.
Greater Than > x > y Returns true if x is greater than y, else it returns false.
Less Than < x < y Returns true if x is less than y, else it returns false.
Greater Than or Equal To >= x >= y Returns true if x is greater than or equal to y, else it returns false.
Less Than or Equal To <= x <= y Returns true if x is less than or equal to y, else it returns false.

The following are the list of detailed tutorials for Logical Operators.

  • C Equal To Operator
  • C Not Equal Operator
  • C Greater Than Operator
  • C Less Than Operator
  • C Greater Than or Equal To Operator
  • C Less Than or Equal To Operator

Bitwise Operators

C Bitwise Operators are used to perform bitwise operations on integer or char operands. Bitwise operations are done at bit level, meaning, operations like AND, OR, XOR, etc., are done between respective bits of the operands.

The following table specifies symbol, example, and description for each of the Bitwise Operator in C programming.

Bitwise Operation Operator Symbol Example Description
AND & x & y Returns the bitwise AND operation between x and y.
OR | x | y Returns the bitwise OR operation between x and y.
XOR ^ x ^ y Returns the bitwise XOR operation between x and y.
Complement ~ ~x Returns the complement of x.
Left Shift << x << y Returns the result of x left shifted by y number of places.
Right Shift >> x >> y Returns the result of x right shifted by y number of places.

The following are the list of detailed tutorials for Logical Operators.

  • C Bitwise AND Operator
  • C Bitwise OR Operator
  • C Bitwise XOR Operator
  • C Bitwise Complement Operator
  • C Bitwise Left Shift Operator
  • C Bitwise Right Shift Operator

Conclusion

In this C Tutorial, we learned about different types of operators in C programming.