Operators in C ? Types of Operators.

By Shakib Ansari | Date: Sun, Mar 30, 2025

C programming mein operators ka use variables aur values par operations perform karne ke liye hota hai. Operator wo symbols hote hain jo kisi kaam ko perform karte hain, jaise addition, comparison, ya logical decision.

1. Types of Operator

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

1. Arithmetic Operators

Arithmetic Operators mein ham mathematical operations perform karte hain. Like +, - , *, /, and %. Ye sabhi operators usi tarah se kaam karte hai jis tarah se maths mein karte hai. Ye operator kisi bhi built-in data type par operate kar sakte hai jaise. int , float, and double etc.

Example: a = 10 b = 8

  • a+b = 18
  • a-b = 2
  • a*b = 80
  • a/b = 1 (decimal part truncated)
  • a%b = 0 (remainder of division)

2. Relational Operators

Relational operators two values ko compare karte hain aur true(1) ya false(0) return karte hain.

Expression: a < b or 1 < 20

Ye ek relational expression hai.

Relational expression ki value ya to one ya zero hoti hai. Ye one hogi agar specified relation true hai aur zero agar relation false hai. For example: 10 < 20 is true but 20 < 10 is false.

Relational Operators

  1. < is less than
  2. <= is less than or equal to
  3. > is greater than
  4. >= is greater than or equal to
  5. == is equal to
  6. != is not equal to

Example of relational operators

  • 4.5 < -10 FALSE
  • 4.5 <= 10 TRUE
  • 8 > 16 FALSE
  • -35 >= 0 FALSE
  • 10 == 7+3 TRUE
  • 35 != 35 FALSE

3. Logical Operators

Logical operators multiple conditions ko combine karne ke liye use hote hain.

  • && meaning logical AND
  • || meaning logical OR
  • ! meaning logical NOT

Logical operators && and || tab use hote hai jab hame ek se zyada condition test karni hoti hai decisions lene ke liye.

Example : a > b && x == 0

int age = 20;
if(age > 18 && age < 60) {
  printf("Eligible");
}

4. Assignment Operators

Assignment operators ka use kisi expression ke result ko kisi variable mein assign karne ke liye kiya jaata hai. For example sum = a + b yaha par hamne a aur b ko add karke sum variable mein assign kar diya hai using the = assignment operator.

a = a + 10 Yeh Equivalent hai iske a += 10 .

5. Increment and Decrement Operators

Ye operators value ko 1 se increase ya decrease karte hain. ++ operator adds 1 value, jabki -- subtracts 1 value. Dono hi unary operators hote hai.

++m or m++ , --m or m--;

Increment and Decrement operators ka use mostly for and while loops mein hota hai.

Jab ham ++ or -- ko operand ke pehle lagate hai wo prefix operator hota hai aur jab ham usko operand ke end mein lagate hai tab wo postfix operator hota hai.

Example: ++m; and --m; ek prefix operator hai aur m++; and m-- ek postfix operator hai.

  1. Prefix operator: Prefix operator mein pehle value add or subtract hoti hai then second operation perform hota hai.
  2. Postfix Operator: Postfix operator mein pehle operation hota hai then second value add or subtract hoti hai.

6. Bitwise Operators

Bitwise operators binary (0 and 1) level par kaam karte hain. Ye operators low level programming aur performance optimization mein use hote hain.

  • & AND
  • | OR
  • ^ XOR
  • ~ One's Complement
  • << Left Shift
  • >> Rigth Shift

7. Conditional Operators

Conditional operator if else ki ek short form hoti hai.

Syntex:

condition ? expression1: expression2;

Example:

int a = 10, b = 20;
int max = (a > b) ? a : b;
printf("%d", max); // Output: 20

8. Special Operators

i. sizeof Operator:

sizeof operator variable ya data type ka size (in bytes) batata hai.

printf("%d", sizeof(int)); // Usually 4 bytes

ii. Comma Operator

Comma operator multiple expressions ko ek saath evaluate karta hai.

int a = (1, 2, 3);
printf("%d", a); // Output: 3
About the Author

Hey, what’s up? I am Shakib Ansari, founder of Beyond Man. I love to help others understand what I have in terms of knowledge...

Comments (0)

No comments yet. Be the first to comment!