Operators in C Language (C लैंग्वेज में ऑपरेटर्स)

Introduction to Operators (ऑपरेटर्स का परिचय)

An operator is a special symbol that performs a specific operation on one or more operands. Operators are used to perform mathematical, relational, logical, bitwise, and other operations in C language. An operand may be a variable, constant, or expression on which an operator performs an operation.

ऑपरेटर एक विशेष चिन्ह होता है, जो एक या एक से अधिक ऑपरेंड पर किसी विशेष प्रकार की क्रिया करता है। C लैंग्वेज में ऑपरेटर्स का उपयोग गणितीय, तुलनात्मक, तार्किक, बिटवाइज तथा अन्य ऑपरेशन करने के लिए किया जाता है।

ऑपरेंड वह वैरिएबल, कॉन्स्टेंट या एक्सप्रेशन होता है जिस पर ऑपरेटर कार्य करता है।

Example:

int a = 10, b = 5;
int c = a + b;

Here, + is an operator, while a and b are operands.

यहाँ + एक ऑपरेटर है तथा a और b इसके ऑपरेंड हैं।

Classification of Operators in C (C में ऑपरेटर्स का वर्गीकरण)

Operators in C language can be classified on two different bases:

  1. On the basis of the number of operands.

  2. On the basis of their applications or functionality.

C लैंग्वेज में ऑपरेटर्स को मुख्य रूप से दो आधारों पर वर्गीकृत किया जाता है:

  1. ऑपरेंड की संख्या के आधार पर।

  2. उनके उपयोग अथवा कार्य के आधार पर।


A. Types of Operators on the Basis of Number of Operands

ऑपरेंड की संख्या के आधार पर ऑपरेटर्स के प्रकार

1. Unary Operator (यूनरी ऑपरेटर)

An operator that performs an operation on a single operand is called a Unary Operator.

जो ऑपरेटर केवल एक ऑपरेंड पर कार्य करता है, उसे यूनरी ऑपरेटर कहते हैं।

Examples: Unary +, Unary -, ++, --, !, ~, sizeof, &, * (in pointer expressions).

Example 1:

#include <stdio.h>
int main(void)
{
int a = 5, b = 7;
a++;
--b;
printf("Value of a = %d\n", a);
printf("Value of b = %d\n", b);
return 0;
}

Output:

Value of a = 6
Value of b = 6

Explanation:

  • a++ increases the value of a by 1.

  • --b decreases the value of b by 1.

व्याख्या:

  • a++ से a का मान 1 बढ़ जाता है।

  • --b से b का मान 1 कम हो जाता है।

2. Binary Operator (बाइनरी ऑपरेटर)

An operator that performs an operation on two operands is called a Binary Operator.

जो ऑपरेटर दो ऑपरेंड पर कार्य करता है, उसे बाइनरी ऑपरेटर कहते हैं।

Examples: Binary +, Binary -, *, /, %, >, <, ==, &&, || etc.

Example:

#include <stdio.h>
int main(void)
{
int a = 5, b = 7, c;
c = a + b;
printf("Addition = %d\n", c);
c = a - b;
printf("Subtraction = %d\n", c);
return 0;
}

Output:

Addition = 12
Subtraction = -2

Explanation:

  • a + b adds two operands.

  • a - b subtracts the second operand from the first operand.

व्याख्या:

  • a + b दो ऑपरेंड को जोड़ता है।

  • a - b पहले ऑपरेंड में से दूसरे ऑपरेंड को घटाता है।

Important Note: The same symbol may work as a unary or binary operator depending on its use. For example, -a uses unary minus, whereas a-b uses binary subtraction.

महत्वपूर्ण नोट: एक ही चिन्ह का उपयोग उसके प्रयोग के अनुसार यूनरी या बाइनरी ऑपरेटर के रूप में हो सकता है। उदाहरण के लिए, -a में Unary Minus तथा a-b में Binary Subtraction का प्रयोग होता है।

3. Ternary Operator (टर्नरी ऑपरेटर)

The Ternary Operator is a conditional operator that works with three operands. It is represented by ?: and is also known as the conditional operator.

टर्नरी ऑपरेटर एक कंडीशनल ऑपरेटर है, जो तीन ऑपरेंड पर कार्य करता है। इसे ?: से दर्शाया जाता है तथा इसे कंडीशनल ऑपरेटर भी कहते हैं।

It is commonly used as a short alternative to a simple if...else statement.

इसका उपयोग सामान्यतः साधारण if...else स्टेटमेंट के संक्षिप्त विकल्प के रूप में किया जाता है।

Syntax:

condition ? expression1 : expression2;
  • If the condition is true, expression1 is evaluated.

  • If the condition is false, expression2 is evaluated.

  • यदि कंडीशन सत्य होती है, तो expression1 का मूल्यांकन किया जाता है।

  • यदि कंडीशन असत्य होती है, तो expression2 का मूल्यांकन किया जाता है।

Example:

#include <stdio.h>
int main(void)
{
int x = 10, y = 20;
(x > y) ?
printf("%d is greater\n", x) :
printf("%d is greater\n", y);
return 0;
}

Output:

20 is greater

Explanation:

The condition x > y is false because 10 is not greater than 20. Therefore, the expression after : is executed.

व्याख्या:

x > y कंडीशन असत्य है क्योंकि 10, 20 से बड़ा नहीं है। इसलिए : के बाद वाला एक्सप्रेशन निष्पादित होता है।


B. Types of Operators on the Basis of Applications

अनुप्रयोग के आधार पर ऑपरेटर्स के प्रकार

C language provides different operators for performing different types of operations. These are commonly classified into the following categories:

C लैंग्वेज में विभिन्न प्रकार के ऑपरेशन करने के लिए अलग-अलग ऑपरेटर्स उपलब्ध हैं। इन्हें सामान्यतः निम्नलिखित श्रेणियों में वर्गीकृत किया जाता है:

  1. Arithmetic Operators (अंकगणितीय ऑपरेटर्स)

  2. Relational Operators (तुलनात्मक ऑपरेटर्स)

  3. Logical Operators (तार्किक ऑपरेटर्स)

  4. Bitwise Operators (बिटवाइज ऑपरेटर्स)

  5. Assignment Operators (असाइनमेंट ऑपरेटर्स)

  6. Miscellaneous Operators (अन्य ऑपरेटर्स)

1. Arithmetic Operators (अंकगणितीय ऑपरेटर्स)

Arithmetic operators are used to perform mathematical operations such as addition, subtraction, multiplication, division, and modulus.

अंकगणितीय ऑपरेटर्स का उपयोग जोड़, घटाव, गुणा, भाग तथा शेषफल जैसी गणितीय क्रियाएँ करने के लिए किया जाता है।

Arithmetic Operators in C:

OperatorOperationExample
+Addition (जोड़)a + b
-Subtraction (घटाव)a - b
*Multiplication (गुणा)a * b
/Division (भाग)a / b
%Modulus (शेषफल)a % b

Example:

#include <stdio.h>
int main(void)
{
int a = 10, b = 3;
printf("Addition = %d\n", a + b);
printf("Subtraction = %d\n", a - b);
printf("Multiplication = %d\n", a * b);
printf("Division = %d\n", a / b);
printf("Modulus = %d\n", a % b);
return 0;
}

Output:

Addition = 13
Subtraction = 7
Multiplication = 30
Division = 3
Modulus = 1

Explanation:

  • 10 + 3 = 13

  • 10 - 3 = 7

  • 10 * 3 = 30

  • 10 / 3 = 3 (Integer division discards the fractional part.)

  • 10 % 3 = 1 (Remainder is 1.)

व्याख्या:

  • 10 + 3 = 13 (जोड़)

  • 10 - 3 = 7 (घटाव)

  • 10 * 3 = 30 (गुणा)

  • 10 / 3 = 3 (पूर्णांक भाग में दशमलव भाग हट जाता है।)

  • 10 % 3 = 1 (शेषफल 1 है।)

Important Points:

  1. The modulus operator % is used with integer operands in C.

  2. Division by zero is not valid.

  3. Integer division discards the fractional part.

महत्वपूर्ण बातें:

  1. C में Modulus ऑपरेटर % का उपयोग पूर्णांक ऑपरेंड के साथ किया जाता है।

  2. शून्य से भाग देना मान्य नहीं है।

  3. पूर्णांक भाग में दशमलव भाग हट जाता है।

2. Relational Operators (तुलनात्मक ऑपरेटर्स)

Relational operators are used to compare two operands. The result of a relational operation is either 1 (true) or 0 (false).

रिलेशनल ऑपरेटर्स का उपयोग दो ऑपरेंड के बीच तुलना करने के लिए किया जाता है। रिलेशनल ऑपरेशन का परिणाम 1 (सत्य) या 0 (असत्य) होता है।

Relational Operators in C:

OperatorMeaningExample
>Greater than (से बड़ा)a > b
<Less than (से छोटा)a < b
>=Greater than or equal to (से बड़ा या बराबर)a >= b
<=Less than or equal to (से छोटा या बराबर)a <= b
==Equal to (बराबर)a == b
!=Not equal to (बराबर नहीं)a != b

Example:

#include <stdio.h>
int main(void)
{
int a = 10, b = 5;
printf("a > b = %d\n", a > b);
printf("a < b = %d\n", a < b);
printf("a >= b = %d\n", a >= b);
printf("a <= b = %d\n", a <= b);
printf("a == b = %d\n", a == b);
printf("a != b = %d\n", a != b);
return 0;
}

Output:

a > b = 1
a < b = 0
a >= b = 1
a <= b = 0
a == b = 0
a != b = 1

Explanation:

Since a = 10 and b = 5, the expressions a > b, a >= b, and a != b are true. The other expressions are false.

व्याख्या:

चूँकि a = 10 तथा b = 5 हैं, इसलिए a > b, a >= b तथा a != b सत्य हैं। अन्य एक्सप्रेशन असत्य हैं।

Important Note: Do not confuse = with ==.

  • = is an assignment operator.

  • == is a relational operator used for comparison.

महत्वपूर्ण नोट: = तथा == में अंतर समझना आवश्यक है।

  • = का उपयोग मान असाइन करने के लिए होता है।

  • == का उपयोग दो मानों की तुलना करने के लिए होता है।

3. Logical Operators (तार्किक ऑपरेटर्स)

Logical operators are used to combine or reverse conditions. They are commonly used with conditional statements such as if, if...else, and loops.

लॉजिकल ऑपरेटर्स का उपयोग एक या अधिक कंडीशन को जोड़ने अथवा किसी कंडीशन के परिणाम को उलटने के लिए किया जाता है। इनका उपयोग सामान्यतः if, if...else तथा लूप्स में किया जाता है।

Logical Operators in C:

OperatorNameMeaning
&&Logical ANDदोनों कंडीशन सत्य हों
`
`Logical ORकम से कम एक कंडीशन सत्य हो
!Logical NOTपरिणाम को उलट देता है

Truth Table of Logical Operators (लॉजिकल ऑपरेटर्स की ट्रुथ टेबल)

Logical AND (&&)

ABA && B
000
010
100
111

Logical OR (||)

ABA || B
000
011
101
111

Logical NOT (!)

A!A
01
10

Example:

#include <stdio.h>
int main(void)
{
int a = 10, b = 5;
printf("Logical AND = %d\n", (a > 5 && b < 10));
printf("Logical OR = %d\n", (a < 5 || b < 10));
printf("Logical NOT = %d\n", !(a > b));
return 0;
}

Output:

Logical AND = 1
Logical OR = 1
Logical NOT = 0

Explanation:

  • (a > 5 && b < 10) is true because both conditions are true.

  • (a < 5 || b < 10) is true because the second condition is true.

  • !(a > b) is false because a > b is true and NOT reverses the result.

व्याख्या:

  • (a > 5 && b < 10) सत्य है क्योंकि दोनों कंडीशन सत्य हैं।

  • (a < 5 || b < 10) सत्य है क्योंकि दूसरी कंडीशन सत्य है।

  • !(a > b) असत्य है क्योंकि a > b सत्य है और NOT इसका परिणाम उलट देता है।

Important Note: Logical operators in C use short-circuit evaluation. In A && B, if A is false, B is not evaluated. In A || B, if A is true, B is not evaluated.

महत्वपूर्ण नोट: C में लॉजिकल ऑपरेटर्स Short-Circuit Evaluation का उपयोग करते हैं। A && B में यदि A असत्य है, तो B का मूल्यांकन नहीं होता। A || B में यदि A सत्य है, तो B का मूल्यांकन नहीं होता।

4. Bitwise Operators (बिटवाइज ऑपरेटर्स)

Bitwise operators perform operations on individual bits of integer operands. These operators work at the binary level.

बिटवाइज ऑपरेटर्स पूर्णांक ऑपरेंड के अलग-अलग बिट्स पर ऑपरेशन करते हैं। ये ऑपरेटर्स बाइनरी स्तर पर कार्य करते हैं।

Bitwise Operators in C:

OperatorNameDescription
&Bitwise ANDदोनों बिट 1 होने पर परिणाम 1
|Bitwise ORकिसी एक बिट के 1 होने पर परिणाम 1
^Bitwise XORदोनों बिट अलग होने पर परिणाम 1
~Bitwise NOTप्रत्येक बिट को उलट देता है
<<Left Shiftबिट्स को बाईं ओर शिफ्ट करता है
>>Right Shiftबिट्स को दाईं ओर शिफ्ट करता है

Example:

Consider two integer values:

a = 5 = 0101
b = 3 = 0011

Bitwise AND (&)

0101
& 0011
------
0001

Result = 1

Bitwise OR (|)

0101
| 0011
------
0111

Result = 7

Bitwise XOR (^)

0101
^ 0011
------
0110

Result = 6

Left Shift (<<)

5 << 1 = 10

Right Shift (>>)

5 >> 1 = 2

C Program:

#include <stdio.h>
int main(void)
{
unsigned int a = 5, b = 3;
printf("Bitwise AND = %u\n", a & b);
printf("Bitwise OR = %u\n", a | b);
printf("Bitwise XOR = %u\n", a ^ b);
printf("Left Shift = %u\n", a << 1);
printf("Right Shift = %u\n", a >> 1);
return 0;
}

Output:

Bitwise AND = 1
Bitwise OR = 7
Bitwise XOR = 6
Left Shift = 10
Right Shift = 2

Explanation:

Bitwise operators perform operations on the binary representation of integer values. For example, 5 & 3 produces 1.

व्याख्या:

बिटवाइज ऑपरेटर्स पूर्णांक मानों के बाइनरी रूप पर कार्य करते हैं। उदाहरण के लिए, 5 & 3 का परिणाम 1 होता है।

Important Note: Bitwise operators should not be confused with logical operators.

  • & is Bitwise AND, whereas && is Logical AND.

  • | is Bitwise OR, whereas || is Logical OR.

  • ^ is Bitwise XOR.

महत्वपूर्ण नोट: Bitwise तथा Logical ऑपरेटर्स को एक समान नहीं समझना चाहिए।

  • & Bitwise AND है, जबकि && Logical AND है।

  • | Bitwise OR है, जबकि || Logical OR है।

  • ^ Bitwise XOR है।

5. Assignment Operators (असाइनमेंट ऑपरेटर्स)

Assignment operators are used to assign values to variables. The simple assignment operator is =, while compound assignment operators combine an operation with assignment.

असाइनमेंट ऑपरेटर्स का उपयोग वैरिएबल में मान असाइन करने के लिए किया जाता है। साधारण असाइनमेंट ऑपरेटर = है, जबकि Compound Assignment Operators किसी ऑपरेशन को असाइनमेंट के साथ जोड़ते हैं।

Assignment Operators in C:

OperatorExampleEquivalent Expression
=a = 10Assigns 10 to a
+=a += 5a = a + 5
-=a -= 5a = a - 5
*=a *= 5a = a * 5
/=a /= 5a = a / 5
%=a %= 5a = a % 5
&=a &= 5a = a & 5
|=a |= 5a = a | 5
^=a ^= 5a = a ^ 5
<<=a <<= 1a = a << 1
>>=a >>= 1a = a >> 1

Example:

#include <stdio.h>
int main(void)
{
int a = 10;
a += 5;
printf("After += : %d\n", a);
a -= 3;
printf("After -= : %d\n", a);
a *= 2;
printf("After *= : %d\n", a);
a /= 4;
printf("After /= : %d\n", a);
a %= 3;
printf("After %%= : %d\n", a);
return 0;
}

Output:

After += : 15
After -= : 12
After *= : 24
After /= : 6
After %= : 0

Explanation:

  • Initially, a = 10.

  • a += 5 makes a = 15.

  • a -= 3 makes a = 12.

  • a *= 2 makes a = 24.

  • a /= 4 makes a = 6.

  • a %= 3 makes a = 0.

व्याख्या:

  • प्रारंभ में a = 10 है।

  • a += 5 से a = 15 हो जाता है।

  • a -= 3 से a = 12 हो जाता है।

  • a *= 2 से a = 24 हो जाता है।

  • a /= 4 से a = 6 हो जाता है।

  • a %= 3 से a = 0 हो जाता है।

6. Miscellaneous Operators (अन्य ऑपरेटर्स)

C language provides some additional operators that are used for specific purposes. These are commonly discussed under miscellaneous operators.

C लैंग्वेज में कुछ अन्य ऑपरेटर्स भी उपलब्ध हैं जिनका उपयोग विशेष कार्यों के लिए किया जाता है। इन्हें सामान्यतः Miscellaneous Operators के अंतर्गत समझाया जाता है।

Important Miscellaneous Operators:

OperatorNamePurpose
sizeofSize Operatorकिसी डेटा टाइप या ऑब्जेक्ट का आकार बताता है
&Address-of Operatorवैरिएबल का मेमोरी एड्रेस प्राप्त करता है
*Pointer Dereference Operatorपॉइंटर द्वारा दर्शाए गए मान तक पहुँचता है
,Comma Operatorएक्सप्रेशन का मूल्यांकन क्रम से करता है
.Member Access OperatorStructure/Union के सदस्य तक पहुँचता है
->Pointer Member Access OperatorStructure/Union पॉइंटर के सदस्य तक पहुँचता है
[]Subscript OperatorArray के तत्व तक पहुँचता है
()Function Call OperatorFunction को कॉल करता है

(a) sizeof Operator

The sizeof operator returns the size, in bytes, of a data type or object.

sizeof ऑपरेटर किसी डेटा टाइप या ऑब्जेक्ट का आकार बाइट्स में बताता है।

Example:

#include <stdio.h>
int main(void)
{
int a;
printf("Size of int = %zu bytes\n", sizeof(int));
printf("Size of variable a = %zu bytes\n", sizeof(a));
return 0;
}

Note: The exact size of a data type depends on the implementation and compiler.

नोट: किसी डेटा टाइप का वास्तविक आकार कंपाइलर और सिस्टम के अनुसार अलग हो सकता है।

(b) Address-of Operator (&)

The address-of operator & returns the memory address of a variable.

Address-of ऑपरेटर & किसी वैरिएबल का मेमोरी एड्रेस प्राप्त करता है।

Example:

int a = 10;
int *p = &a;

Here, &a gives the address of variable a.

यहाँ &a वैरिएबल a का मेमोरी एड्रेस देता है।

(c) Pointer Dereference Operator (*)

The dereference operator * is used to access the value stored at the memory address held by a pointer.

Dereference ऑपरेटर * का उपयोग पॉइंटर में संग्रहित मेमोरी एड्रेस पर मौजूद मान को प्राप्त करने के लिए किया जाता है।

Example:

int a = 10;
int *p = &a;
printf("%d", *p);

Output:

10

(d) Comma Operator (,)

The comma operator evaluates expressions from left to right and produces the value of the last expression.

Comma ऑपरेटर एक्सप्रेशन्स का मूल्यांकन बाएँ से दाएँ करता है तथा अंतिम एक्सप्रेशन का मान परिणाम के रूप में देता है।

Example:

#include <stdio.h>
int main(void)
{
int a;
a = (5, 10, 15);
printf("Value of a = %d", a);
return 0;
}

Output:

Value of a = 15

(e) Member Access Operators (. and ->)

The dot operator . is used to access a structure or union member through a structure or union variable. The arrow operator -> is used to access a member through a pointer to a structure or union.

Dot ऑपरेटर . का उपयोग Structure या Union वैरिएबल के सदस्य तक पहुँचने के लिए किया जाता है। Arrow ऑपरेटर -> का उपयोग Structure या Union के पॉइंटर के माध्यम से सदस्य तक पहुँचने के लिए किया जाता है।

Example:

struct Student
{
int roll;
};
struct Student s = {101};
struct Student *p = &s;
/* s.roll accesses the member using a variable */
/* p->roll accesses the member using a pointer */

(f) Subscript Operator ([])

The subscript operator [] is used to access elements of an array.

Subscript ऑपरेटर [] का उपयोग Array के तत्वों तक पहुँचने के लिए किया जाता है।

Example:

int arr[3] = {10, 20, 30};
printf("%d", arr[1]);

Output:

20

(g) Function Call Operator (())

Parentheses () are used to call a function and pass arguments to it.

Parentheses () का उपयोग किसी Function को कॉल करने तथा उसमें Arguments पास करने के लिए किया जाता है।

Example:

printf("Hello C");

Output:

Hello C

Difference Between Unary, Binary and Ternary Operators

यूनरी, बाइनरी तथा टर्नरी ऑपरेटर्स में अंतर

BasisUnary OperatorBinary OperatorTernary Operator
Number of operandsOneTwoThree
हिंदीएक ऑपरेंडदो ऑपरेंडतीन ऑपरेंड
Example++aa + ba > b ? a : b
Common useSingle operand operationTwo operand operationConditional expression

Important Points for CPCT, Exams and Interviews

CPCT, परीक्षाओं एवं इंटरव्यू के लिए महत्वपूर्ण बातें

  1. An operator performs an operation on one or more operands.
    ऑपरेटर एक या अधिक ऑपरेंड पर ऑपरेशन करता है।

  2. Unary operators work on one operand.
    यूनरी ऑपरेटर एक ऑपरेंड पर कार्य करते हैं।

  3. Binary operators work on two operands.
    बाइनरी ऑपरेटर दो ऑपरेंड पर कार्य करते हैं।

  4. The conditional operator ?: is a ternary operator.
    कंडीशनल ऑपरेटर ?: एक टर्नरी ऑपरेटर है।

  5. The modulus operator % gives the remainder.
    Modulus ऑपरेटर % शेषफल देता है।

  6. Relational operators return either 1 or 0 in C.
    C में रिलेशनल ऑपरेटर्स का परिणाम 1 या 0 होता है।

  7. Logical AND is represented by &&.
    Logical AND को && से दर्शाया जाता है।

  8. Logical OR is represented by ||.
    Logical OR को || से दर्शाया जाता है।

  9. Bitwise XOR is represented by ^.
    Bitwise XOR को ^ से दर्शाया जाता है।

  10. The sizeof operator returns size in bytes.
    sizeof ऑपरेटर आकार को बाइट्स में बताता है।

  11. = is an assignment operator, whereas == is a relational operator.
    = असाइनमेंट ऑपरेटर है, जबकि == रिलेशनल ऑपरेटर है।

  12. ++ is the increment operator and -- is the decrement operator.
    ++ इंक्रीमेंट तथा -- डिक्रीमेंट ऑपरेटर है।


Operators are an essential part of C programming. They help programmers perform arithmetic calculations, compare values, evaluate conditions, manipulate individual bits, assign values, and access memory or data members. A proper understanding of C operators is essential for learning programming logic, conditional statements, loops, arrays, pointers, and data structures.

C प्रोग्रामिंग में ऑपरेटर्स का महत्वपूर्ण स्थान है। इनकी सहायता से गणितीय गणनाएँ, मानों की तुलना, कंडीशन का मूल्यांकन, बिट्स में बदलाव, मान असाइन करना तथा मेमोरी और डेटा मेंबर तक पहुँचना संभव होता है। C ऑपरेटर्स की अच्छी समझ Programming Logic, Conditional Statements, Loops, Arrays, Pointers तथा Data Structures सीखने के लिए आवश्यक है।

Comments

Popular posts from this blog

C Language Topics in Hindi and English

Complete C Programming Syllabus | Advanced C Roadmap for Students

Top High-Paying Tech Skills to Learn in 2025