Home » C Programming » Operators in C: Definition, Types, and Examples

Operators in C: Definition, Types, and Examples

Operators in C: Definition, List, and Examples

In C programming, an operator is a special symbol used to perform operations on variables and values. Operators are the building blocks of expressions and help in performing calculations, comparisons, and logical decisions.

int a = 10, b = 5;
int sum = a + b; // '+' is the operator

Complete List of Operators in C

  • Arithmetic Operators: +, -, *, /, %
  • Relational Operators: ==, !=, >, <, >=, <=
  • Logical Operators: &&, ||, !
  • Assignment Operators: =, +=, -=, *=, /=, %=, &=, |=, ^=, <<=, >>=
  • Increment/Decrement Operators: ++, —
  • Bitwise Operators: &, |, ^, ~, <<, >>
  • Conditional (Ternary) Operator: ? :
  • Special Operators: sizeof, &, *, ., ->, , (comma)

Operators in C with Examples

1. Arithmetic Operators

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

2. Relational Operators

OperatorDescriptionExample (a=10, b=5)Result
==Equal toa == b0 (false)
!=Not equal toa != b1 (true)
>Greater thana > b1 (true)
<Less thana < b0 (false)
>=Greater or equala >= b1 (true)
<=Less or equala <= b0 (false)

3. Logical Operators

OperatorDescriptionExampleResult
&&Logical AND(a > 5 && b > 2)1 (true)
||Logical OR(a > 5 || b > 10)1 (true)
!Logical NOT!(a > b)0 (false)

4. Assignment Operators

OperatorExampleMeaning
=a = 10Assign 10 to a
+=a += 5a = a + 5
-=a -= 5a = a – 5
*=a *= 5a = a * 5
/=a /= 5a = a / 5
%=a %= 5a = a % 5
&=a &= 2a = a & 2
|=a |= 2a = a | 2
^=a ^= 2a = a ^ 2
<<=a <<= 1a = a << 1
>>=a >>= 1a = a >> 1

5. Increment and Decrement Operators

OperatorDescriptionExample (a=10)Result
++aPre-increment++a11
a++Post-incrementa++10 (then a=11)
–aPre-decrement–a9
a–Post-decrementa–10 (then a=9)

6. Bitwise Operators

OperatorDescriptionExample (a=5, b=3)Result
&Bitwise ANDa & b1
|Bitwise ORa | b7
^Bitwise XORa ^ b6
~Bitwise NOT~a-6
<<Left shifta << 110
>>Right shifta >> 12

7. Conditional (Ternary) Operator

Syntax:

condition ? expression1 : expression2;

Example:

int result = (a > b) ? a : b; // returns max of a and b

8. Special Operators

  • sizeof → returns size of a data type or variable
  • & → address of variable
  • * → pointer (value at address)
  • . → access structure member
  • -> → access structure member through pointer
  • , → comma operator (separates expressions)

Leave a comment

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