C Operators

The operator is simply a symbol that tells the C compiler to perform relational, mathematical or logical operations. To perform these operations, C language provides the following operators.

C Operators
C Operators

The operator is simply a symbol that tells the C compiler to perform relational, mathematical or logical operations. To perform these operations, C language provides the following operators.

  • Arithmetic Operators
  • Relational Operators
  • Logical Operators
  • Bitwise Operators
  • Assignment Operators

Arithmetic Operators

Arithmetic Operators are used to perform mathematical operations such as (+, -, *, /, etc.).

Operator Description
+ operator is used to add two operands.
operator is used to subtract second operand
from first operand.
* operator is used to multiplies two operands.
/ / operator is used to divides number on its left
by the number on its right and returns a value.
% % modulus operator is also called the remainder
operator, which returns the remainder when the
first operand is divided by the second operand.
++ ++ is an increment operator that is used to increase
the integer value by one.
— is a decrement operator that is used to decrease
the integer value by one.

Relational Operators

Relational operators are used to creating a test expression that controls the program flow. Relational operators are also called as a boolean expression because relational operator returns boolean answers. (Eg: Assume a=10, b=10, (a==b) will return true).

Operator Description
== If both the values in the operand are equal
then the condition becomes true.
!= If both the values in the operands are not
equal then the condition becomes true.
> If the value of the left operand is greater
than the value of right operand, then the
condition becomes true.
< If the value of the left operand is less than
the value of right operand, then the condition
becomes true.
>= If the value of left operand is greater than or
equal to the right operand, then the condition
becomes true.
<= If the value of left operand is less than or equal
to the right operand, then the condition
becomes true.

Logical Operators

The logical operator is a word or symbol which is used to connect two or more expressions. The logical operator is mainly used to control the program flow. Common logical operators are AND, OR, and NOT.

Operator Description
&& logical AND operator, if both the operands
are non-zero then the condition will
become true.
|| logical OR operator, if any one of the two
operands is non-zero then the condition
becomes true.
! logical NOT operator, if a condition is false,
the NOT operator will make it as true.
Simply the logical NOT operator is used
to reverse the logical statements result.

Bitwise Operators

Bitwise operators are used to changing individual bits in an operand. Bitwise operators perform on bit patterns or binary numerals that involve the manipulation of individual bits.

Operator Description
& (bitwise AND) Bitwise AND operator takes two numbers
as operands and copies a bit to the result
only if it exists on both side.
| (bitwise OR) Bitwise OR operator takes two numbers as
operands and copies a bit to the result
only if it exists on either side.
^ (bitwise XOR) Bitwise XOR operator takes two numbers
as operands and copies a bit to the result
only if it exists one side but not both.
<< (left shift) Bitwise left shift operator takes two numbers.
The left operand value is moved to the left by
the number of bits specified by the right operand.
>>(right shift) Bitwise right shift operator takes two numbers.
The left operand value is moved to the right by
the number of bits specified by the right operand.
~ (bitwise NOT) Bitwise NOT operator takes one number and inverts all bits.

Assignment Operators

Assignment operators are used to assign value to a variable. The commonly used assignment operator is =.

Operator Description
= This operator assign the value from the right to left.
+= This operand adds the right operand to the left and
assign the value to left operand.
-= This operand subtract the right operand to the left and
assign the value to left operand.
*= This operand multiply the right operand to the left and
assign the value to left operand.
/= This operand divide the right operand to the left and
assign the value to left operand.
%= This operand takes the modulus from both the operand
and assign values to left operand.