Namaskar Dosto!
Agar aap C programming seekh rahe ho, toh “Operators” ek aisa topic hai jo aapko har hal mein samajhna hi chahiye. Kyunki aage ke maximum concepts chahe woh conditions ho, loops ho ya expressions sabhi mein operators ka use hota hai.
Is article mein hum bilkul beginner-friendly tareeke se samjhenge:
- Operators Kya Hote Hain?
- Operators Ke Kitne Types Hote Hain?
Jaisa,
• Arithmetic Operators
• Relational Operators
• Logical Operators
• Bitwise Operators
• Assignment Operators
• Increment & Decrement Operators
• Conditional (Ternary) Operator
• Comma Operator
• Sizeof Operator
• Pointer Operators - Operator Precedence Aur Associativity
- FAQs (Frequently Asked Questions)
Toh dosto chaliye bina kisi deri ke C Language ke Operators ko achhe se samajhna shuru karte hain!
Operators Kya Hote Hain?
C Language mein operators woh symbols hote hain jo kisi bhi variable ya value par koi operation perform karte hain. Ye operations ho sakte hain:
Addition, subtraction, comparison, logical checks, value assign karna, etc.
Jaise tum Maths mein + ka use addition ke liye karte ho, waise hi programming mein bhi + ek operator hai.
Example Se Samjho:
int a = 10;
int b = 5;
int sum = a + b; // Yahan '+' operator do numbers ko add kar raha hai
Yaha:
+ ek operator hai
a aur b operands hain
sum ek variable hai jisme result store hoga
Operators Ke Kitne Types Hote Hain?
C Programming Language mein Operators ko unke use ke hisaab se 10 alag-alag categories mein divide kiya gaya hai. Har ek operator ka apna specific kaam hota hai, jaise calculation karna, comparison karna, memory address check karna, etc.
Dosto, Chaliye ek-ek karke har operator ko samajhte hain simple Hinglish mein:
1. Arithmetic Operators
Ye operators maths wale basic kaam karte hain — Addition, Subtraction, Multiplication, Division, aur Modulus.
Operator | Kaam (Use) | Example |
---|---|---|
+ | Add karna | a + b |
- | Subtract karna | a – b |
* | Multiply karna | a * b |
/ | Divide karna | a / b |
% | Remainder lena | a % b |
2. Relational Operators
Ye operators do values ke beech comparison karte hain aur result hamesha true (1) ya false (0) hota hai.
Operator | Kaam (Use) | Example |
---|---|---|
== | Equal to | a == b |
!= | Not equal to | a != b |
> | Greater than | a > b |
< | Less than | a < b |
>= | Greater than or equal | a >= b |
<= | Less than or equal | a <= b |
3. Logical Operators
Ye operators multiple conditions ke sath kaam karte hain — jaise dono condition true ho, ya koi ek ho, ya na ho.
Operator | Meaning | Example |
---|---|---|
&& | AND | a > 5 && b < 10 |
|| | OR | a>5 || b<15 |
! | NOT (Ulta kare) | !(a == b) |
4. Bitwise Operators
Ye operators variables ke binary bits par kaam karte hain. Ye mostly low-level programming mein use hote hain.
Operator | Meaning |
---|---|
& | Bitwise AND |
^ | Bitwise XOR |
~ | Bitwise NOT |
<< | Left Shift |
>> | Right Shift |
5. Assignment Operators
Inka use value assign karne ke liye hota hai. Simple bhi hote hain aur short form wale compound bhi.
Operator | Meaning | Example |
---|---|---|
= | Assign value | a = 10 |
+= | Add and assign | a += 5 |
-= | Subtract and assign | a -= 3 |
*= | Multiply and assign | a *= 2 |
/= | Divide and assign | a /= 4 |
%= | Modulus and assign | a %= 3 |
6. Increment & Decrement Operators
Ye kisi variable ko 1 se badhane ya ghatane ke kaam aate hain.
Operator | Use | Example |
---|---|---|
++ | Add 1 (Increment) | a++ or ++a |
-- | Subtract 1 | a– or –a |
Extra Knowledge:
++a (Pre Increment Operator), a++ (Post Increment Operator),–a (Pre Decrement Operator), a— (Post DecrementOperator),
7. Conditional (Ternary) Operator
Ye operator ek short form if-else hota hai. Ek hi line mein condition check aur value assign karta hai.
Syntax:
condition ? expression1 : expression2
- Agar condition true hai, to expression1 execute hoga.
- Agar condition false hai, to expression2 execute hoga.
Example:
#include <stdio.h>
int main()
{
int a = 10, b = 20;
// Using the ternary operator to find the larger number
int max = (a > b) ? a : b;
printf("The larger number is: %d\n", max);
return 0;
}
8. Comma Operator ,
Ye operator multiple expressions ko ek hi line mein likhne ke liye use hota hai.
Sabhi expressions evaluate hote hain, lekin sirf last expression ka result return hota hai.
Example:
#include <stdio.h>
int main() {
int x = 5;
int y = (x++, x + 2, x * 2); // Multiple expressions separated by commas
printf("The value of y is: %d\n", y);
return 0;
}
9. sizeof
Operator
sizeof
operator ka use variable, data type ya array ka size (in bytes) pata karne ke liye hota hai — aur ye compile time par evaluate hota hai.
Example 1:
#include <stdio.h>
int main() {
printf("Size of int: %lu bytes\n", sizeof(int)); // Typically 4 bytes
printf("Size of float: %lu bytes\n", sizeof(float)); // Typically 4 bytes
printf("Size of double: %lu bytes\n", sizeof(double)); // Typically 8 bytes
printf("Size of char: %lu bytes\n", sizeof(char)); // Typically 1 byte
return 0;
}
Example 2:
#include <stdio.h>
int main() {
int a;
double b;
printf("Size of variable 'a' (int): %lu bytes\n", sizeof(a));
printf("Size of variable 'b' (double): %lu bytes\n", sizeof(b));
return 0;
}
Example 3:
#include <stdio.h>
int main() {
int arr[5];
printf("Size of array: %lu bytes\n", sizeof(arr));
printf("Size of one element: %lu bytes\n", sizeof(arr[0]));
return 0;
}
10. Pointer Operators: &
(Address-of), *
(Dereference)
&
(Address-of Operator):
- Ye operator kisi variable ka memory address find karne ke liye use hota hai.
*
(Dereference Operator):
- Ye operator pointer ke through address se value access karta hai.
Example:
#include <stdio.h>
int main() {
int a = 10;
int *p; // Pointer declaration
p = &a; // Using the & operator to store the address of 'a' in pointer 'p'
printf("Value of a: %d\n", a);
printf("Address of a: %p\n", (void*)&a);
printf("Address stored in pointer p: %p\n", (void*)p);
printf("Value pointed to by p: %d\n", *p);
return 0;
}
Explanation:
&a
ka matlab hota hai: a ka memory addressp = &a
ka matlab hota hai: p mein a ka address store karna*p
ka matlab hota hai: p mein stored address par jo value hai, usko access karna
Operator Precedence Aur Associativity
- Operators ke paas precedence (priority) hoti hai jo yeh decide karti hai ki expression mein pehle kaunsa operator evaluate hoga.
- Associativity yeh batata hai ki jab same precedence wale multiple operators ho, to unka evaluation left to right hoga ya right to left.
Example:
int a = 5 + 2 * 3; // * ka precedence + se zyada hai, isliye pehle 2 * 3 evaluate hoga
FAQs (Frequently Asked Questions)
1. C bhasha mein operator kya hota hai?
C language mein operator ek special symbol hota hai jo variables ya values par kuch specific operation perform karta hai. Jaise addition (+
), comparison (==
), assignment (=
) ya logical check (&&
) ye sab operators ke example hain. Inka use expressions banane ke liye hota hai.
2. C language mein operators kitne types ke hote hain?
C language mein total 10 types ke operators hote hain:
1. Arithmetic Operators
2. Relational Operators
3. Logical Operators
4. Bitwise Operators
5. Assignment Operators
6. Increment/Decrement Operators
7. Conditional (Ternary) Operator
8. Comma Operator
9. sizeof Operator
10.Pointer Operators
3. Arithmetic aur relational operators mein kya antar hai?
Arithmetic operators basic mathematical operations jaise +
, -
, *
, /
, %
perform karte hain.
Relational operators (==
, !=
, <
, >
, <=
, >=
) do values ka comparison karte hain aur result true (1)
ya false (0)
return karte hain.
4. Logical operators C language mein kaise kaam karte hain?
Logical operators (&&
, ||
, !
) ka use multiple conditions ke sath kiya jata hai.
&&
(AND): dono conditions true ho toh hi true||
(OR): koi ek condition true ho toh bhi true!
(NOT): result ko ulta kar deta hai (true → false, false → true)
5. Conditional (ternary) operator kya hota hai aur iska syntax kya hai?
Conditional ya ternary operator ek short form hoti hai if-else ki.
Iska syntax hota hai:
condition ? expression1 : expression2;
6. sizeof operator C language mein kis liye use hota hai?
sizeof
operator ka use kisi bhi variable, data type ya array ka size (bytes mein) pata karne ke liye hota hai.
Example:
printf(“Size of int: %lu”, sizeof(int)); // Mostly 4 bytes
Conclusion
Toh dosto, is article mein humne C language ke sabhi important operators ko simple aur asaan tareeke se samjha. Chahe woh arithmetic ho ya logical, assignment ho ya pointer har operator ka apna ek role hota hai programming mein. Agar aap ye basics ache se samajh lete ho, toh aap aage ke concepts jaise loops, conditions, ya functions ko aur bhi achhe se handle kar paoge.
dosto, Agar aapko yeh article helpful laga ho to ise share karein, comment karein, aur apne dosto ko bhi recommend karein.
Next article kis topic par chahiye? Comment karke zarur batao.
Written by: Aditya (Programming Sikho)
Next Article Padhein: