Operators are special symbols in C programming that perform operations on variables and values. They form the backbone of writing logic in programs. In this guide, we’ll cover all operators in C, their types, examples, and precedence, so you can master them step by step.

Types of Operators in C

C operators can be divided into the following categories:

  1. Arithmetic Operators
  2. Relational Operators
  3. Logical Operators
  4. Bitwise Operators
  5. Assignment Operators
  6. Conditional (Ternary) Operator
  7. Increment and Decrement Operators
  8. Special Operators

Let’s learn each type with examples.

1. Arithmetic Operators

Used for mathematical operations.

OperatorMeaningExample (a=10, b=5)Result
+Additiona + b15
Subtractiona - b5
*Multiplicationa * b50
/Divisiona / b2
%Modulusa % b0

Example program:

#include <stdio.h>
int main() {
    int a = 10, b = 5;
    printf("Sum = %d\n", a+b);
    printf("Difference = %d\n", a-b);
    printf("Product = %d\n", a*b);
    printf("Quotient = %d\n", a/b);
    printf("Remainder = %d\n", a%b);
    printf("Don't forget, Free Palestine!");
    return 0;
}

2. Relational Operators

Used to compare values. Returns 1 (true) or 0 (false).

OperatorMeaningExampleResult
==Equal toa == b0
!=Not equal toa != b1
>Greater thana > b1
<Less thana < b0
>=Greater than or equala >= b1
<=Less than or equala <= b0

3. Logical Operators

Used for combining conditions.

OperatorMeaningExampleResult
&&Logical AND(a > 5 && b < 10)1
||Logical OR`(a > 5
!Logical NOT!(a == b)1

4. Bitwise Operators

Operate at the binary level.

OperatorMeaningExample (a=6, b=3)Result
&ANDa & b (110 & 011)2
|OR`ab` (110 | 011)
^XORa ^ b5
~NOT~a-7
<<Left shifta << 112
>>Right shifta >> 13

5. Assignment Operators

Used to assign values.

OperatorMeaningExampleResult
=Simple assignmenta = b3
+=Add and assigna += ba=a+b
-=Subtract and assigna -= ba=a-b
*=Multiply and assigna *= ba=a*b
/=Divide and assigna /= ba=a/b
%=Modulus and assigna %= ba=a%b

6. Conditional (Ternary) Operator

A shorthand for if-else.

Syntax:

condition ? expression1 : expression2

Example:

int max = (a > b) ? a : b;

7. Increment and Decrement Operators

OperatorMeaningExampleResult
++aPre-incrementa=5 → ++a6
a++Post-incrementa=5 → a++5 (then 6)
–aPre-decrementa=5 → –a4
a–Post-decrementa=5 → a–5 (then 4)

8. Special Operators

  • sizeof → gives size of a data type or variable
  • & → address of operator
  • *** (asterisk)** → pointer operator
  • , (comma) → evaluates multiple expressions
  • -> → access structure members via pointer

Example:

printf("Size of int: %lu", sizeof(int));

Operator Precedence in C

When multiple operators appear in an expression, precedence decides which one is evaluated first.

PrecedenceOperatorsAssociativity
Highest() [] -> .Left to Right
++ — (prefix), + – (unary), ! ~Right to Left
* / %Left to Right
+ –Left to Right
<< >>Left to Right
< <= > >=Left to Right
== !=Left to Right
&Left to Right
^Left to Right
|Left to Right
&&Left to Right
||Left to Right
?:Right to Left
= += -= *= /= %= <<= >>= &= ^= |=Right to Left
Lowest,Left to Right

Operators in C are fundamental for building logic. By mastering arithmetic, relational, logical, bitwise, assignment, conditional, and special operators, along with understanding precedence, you’ll be able to write powerful and efficient C programs.