Operators in C ? Types of Operators.

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

C language bahut saare operators ko support karti hai. Operator ek symbol hota hai jo ki computer ko batata hai ki kiya operation perform karna hai? C language mein bahut types ke operators hote hai jaise Mathematical or logical. Program mein operator ka use data aur variables ki values ko manipulate karna hota hai. Ye usually ek part hote hai mathmatical or logical expressions ka.

C operators kuch categories mein classified ho sakte hai jaise.

  1. Arithmetic operators
  2. Relational operators
  3. Logical operators
  4. Assignment operators
  5. Increment and decrement operators
  6. Conditional operators
  7. Bitwise operators
  8. Special operators

Expression ek combination hota hai operators aur operands ka, jo kisi value ko reduce karke ek single value mein convert karta hai. For example:

10 + 5. Ye ek expression hai jiski value 25. Ye value kisi bhi type ki ho sakti hai other than void.

1. Arithmetic Operators

C hame sare basic operators provide karti hai jaise ki +, - , *, /, and %. Ye sabhi operator usi tarah se kaam karte hai jis tarah se dusri languages mein karte hai. Ye operator kisi bhi built-in data type par operate kar sakte hai jaise. int , float, and double etc.

Integer Operator

Jab dono operands like a+b integers hote hai tab Integer Operator operate karta hai. Ye expression ek integer expression kehlati hai. Integer arithmetic always ek integer value ko hi produce karta hai.Example ke liye a = 14, b=4

  • a-b = 10
  • a+b = 18
  • a*b = 56
  • a/b = 3 (decimal part truncated)
  • a%b = 2 (remainder of division)

2. Relational Operators

Ham normally two quantities ko compare karte hai aur unke relation par depend hokar, ham kuch decisions lete hai. For example, two persons ki age, or two items ka price, and so on. Aise comparisons ham relational operators ki help se kar sakte hai.

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.

C six relational operators ko support karti hai.

  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

Relational operators ke sath C three logical operators ko bhi support karta hai.

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

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

Example : a > b && x == 0

Is type ki expression jisme two or more relational expressions hoti hai wo logical expression or compound relational expression hoti hai. Logical expression bhi zero or one value ko produce karti hai. Above expression true hogi agar a > b true ho aur x == 0 bhi true ho agar in dono mein se koi bhi ek or dono expression false hoti hai to puri expression false ho jaygi. ! Yeh hai NOT operator jo ki puri expression ke output ko opposite kar degi. For example yeh expression a > b && x == 0 true result deta hai agar ham yaha par ! NOT operator append kar dete hain to iska output pura opposite ho jayga jo ki false hoga.

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 + byaha par hamne a aur b ko add karke sum variable mein assign kar diya hai using the = assignment operator.

C language mein 'shorthand' operator bhi hai.

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

5. Increment and Decrement Operators

C language mein two very useful operators hote hai jo ki generally other languages mein nhi hote hai. Ye hai increment and decrement operators: ++ and --

++ operator adds 1 value, jabki -- subtracts 1. Dono hi unary operators hote hai.

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

Ham increment and decrement statements ko bahut zyada for and while loops mein use karte hai.

Jab ham ++ or -- ko operand ke pehle lagate hai wo prefix operator hota hai aur jab ham use 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.

Prefix operator; Prefix operator mein pehle value add or subtract hoti hai then second operation perform hota hai.

x = ++y Yaha par pehle value increment hogi then x variable ko assign hogi same for decrement prefix operator.

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

x = y++ Yaha par pehle x variable ko value assign hogi aur phir y mein increment hoga same for decrement postfix operator.

6. Conditional Operators

C mein ek ternary operator pair "? :" bhi available hota hai jo ki conditional expressions ko form karta hai.For example: exp1 ? exp2: exp3

where exp1, exp2, and exp3 are expressions.

The operator ?: pehle exp1 ko evaluate karega. Agar ye nonzero (true), phir exp2 ko evaluate karega aur ye expression ki value ban jayegi. Agar exp1 false hai, exp3 evaluted hai to ye expression ki value ban jaygi. Yaha is cheez par dihaan do ki yaha ye to exp2 or exp3 hi evaluate hoga dono nhi ho sakte hai.

a = 10

b = 15

x = (a > b) ? a: b;

is example mein, x ko b ki value assign ho jaygi. Yeh ham if..else statements se bhi achive kar sakte hai

-if(a > b)

x = a;

else

x = b;


About the Author

Hi, I'm Shakib Ansari, Founder and CEO of BeyondMan. I'm a highly adaptive developer who quickly learns new programming languages and delivers innovative solutions with passion and precision.

Shakib Ansari
Programming

Comments