C Operators

An operator is a symbol or keyword that tells C to perform an operation.

  1. Arithmetic operators
OperatorMeaningExample (a=10,b=3)
+Additiona + b = 13
–Subtractiona – b = 7
*Multiplicationa * b = 30
/Divisiona / b = 3 (integer division)
%Remaindera % b = 1
  1. Relational operators

These compare two values. In a condition, the result is treated as true or false.

==   equal to
!=   not equal to
>    greater than
<    less than
>=   greater than or equal to
<=   less than or equal to

 

  1. Logical operators
&&   AND  → both conditions must be true
||   OR   → at least one condition is true
!    NOT  → reverses a condition

 

  1. Assignment operators
=    +=    -=    *=    /=    %=

 

  1. Increment and decrement
x++;   // increase by 1
x–;   // decrease by 1

 

  1. Bitwise operators
&    AND
|    OR
^    XOR
~    NOT
<<   left shift
>>   right shift

 

Bitwise operators work on the individual bits of integer values.

  1. Conditional operator
condition ? value_if_true : value_if_false;

 

  1. sizeof
sizeof(variable_or_type)

 

Complete operator program

#include <stdio.h>

int main() {
int a = 10, b = 3;

printf(“Addition = %d\n”, a + b);
printf(“Subtraction = %d\n”, a – b);
printf(“Multiplication = %d\n”, a * b);
printf(“Division = %d\n”, a / b);
printf(“Remainder = %d\n”, a % b);

if (a > b && b > 0) {
printf(“Both conditions are true.\n”);
}

return 0;
}

 

OUTPUT
Addition = 13
Subtraction = 7
Multiplication = 30
Division = 3
Remainder = 1
Both conditions are true.

 

⭐ EASY TIP: The = operator assigns a value. The == operator compares two values. This is one of the most common beginner mistakes.
Scroll to Top