DEV Community

Cover image for Unary operators in C | सी में अनियोजित ऑपरेटर ➕➕
Gajender Tyagi
Gajender Tyagi

Posted on

Unary operators in C | सी में अनियोजित ऑपरेटर ➕➕

This is for my ❤️ Rashi as she is learning coding 💻 I wanted to help her understand concepts in the best way I can.🚀

Using hindi translation with English.

What are Unary operators in c and 🤔 why do we need to learn them?

First we need to understand what is an operator?

पहले हमें यह समझने की जरूरत है कि एक ऑपरेटर क्या है?

  • Simply put an operator is a symbol used to perform a mathematical or logical manipulation on operand.
  • सीधे शब्दों में कहें तो एक ऑपरेटर एक प्रतीक है जो ऑपरेंड पर गणितीय या तार्किक हेरफेर करने के लिए उपयोग किया जाता है।

  • e.g.

    • unary minus(-)
    • increment(++)
    • decrement(- -)
    • NOT(!)
    • Addressof operator(&)
    • sizeof()

What is an operand?

एक ऑपरेंड क्या है?

  • The argument(variable) on which operator acts upon is an operand.
  • वैरिएबल जिस पर ऑपरेटर कार्य करता है वह एक ऑपरेंड है।
  • e.g. -b: In here minus(-) is an operator and 'b' is an operand. a++: In here ++ is an operator and 'a' is an operand.
  • In the above example -b, the minus is giving a negative value to b and in a++ the increment operator(++) is changing the value of a by increment to +1 value. a++ can be written as a = a + 1.

We will look at each of operands and their uses.

हम प्रत्येक ऑपरेंड और उनके उपयोगों को देखेंगे।

Unary minus(-)

Most of us must have first learned about negative numbers in 6th class, as it was taught then the same applies in programming as well. A unary minus changes the sign of its argument(variable).

हम में से अधिकांश ने पहले 6 वीं कक्षा में नकारात्मक संख्याओं के बारे में सीखा होगा, क्योंकि यह सिखाया गया था और साथ ही साथ प्रोग्रामिंग में भी लागू होता है। एक अनुपस्थित माइनस अपने तर्क (चर) के संकेत को बदलता है।

Code to explain ....

 int number1 = 10;
 int number2 = -number1;  // number2 = -10
Enter fullscreen mode Exit fullscreen mode

In above code the operator '-' changes value of +10 to -10.
उपरोक्त कोड में ऑपरेटर '-' +10 से -10 का मान बदलता है।

Similarly ....

 int number1 = -10;
 int number2 = -number1;  // number2 = 10
Enter fullscreen mode Exit fullscreen mode

If applied on a negative number the result will be positive as - + - = +.
यदि माइनस नंबर पर आवेदन किया जाता है तो परिणाम सकारात्मक होगा - + - = +।

Increment(++)

It is used to increase the value of operand by 1. You must be familiar with the mathematical operations such as 4+1 = 5, in c language you must have seen a = a + 1
इसका उपयोग 1 से ऑपरेंड के मूल्य को बढ़ाने के लिए किया जाता है। आपको गणितीय क्रियाओं जैसे 4 + 1 = 5 से परिचित होना चाहिए, सी भाषा में आपने a = a + 1 जरूर देखा होगा।

int number = 5; 
number = number + 1 // number = 6 
Enter fullscreen mode Exit fullscreen mode

In the same manner increment operator works.
उसी तरीके से इंक्रीमेंट ऑपरेटर काम करता है।

int number = 5; 
number++; // number = 6 
Enter fullscreen mode Exit fullscreen mode

decrement(- -)

It is opposite of increment operator. It will decrease the value of operand by 1.
यह प्लस ऑपरेटर के विपरीत है। यह 1 से ऑपरेंड के मूल्य में कमी करेगा।

int number = 6;
int number = number - 1; // number = 5
Enter fullscreen mode Exit fullscreen mode

In the same manner decrement operator works.
उसी तरह माइनस माइनस ऑपरेटर काम करता है।

int number = 5; 
number--; // number = 5
Enter fullscreen mode Exit fullscreen mode

I'm leaving the concept of post and pre increment and decrement for now as understanding one concept before another is important.

**मैं पद और पूर्व वेतन वृद्धि और वेतन वृद्धि की अवधारणा को छोड़ रहा हूं क्योंकि एक अवधारणा को दूसरे से पहले समझना महत्वपूर्ण है। **

NOT(!)

The logical state of an operand is changed by the not operator and it is represented by !.

A value which is true is changed to false and vice-versa.
एक मान जो सत्य है, उसे असत्य और इसके विपरीत में बदल दिया जाता है।

In C language you must have studied about boolean data type, if not please click here.

If x is true, then !x is false
If x is false, then !x is true

Code example....

bool value = true;
bool value2;
value2 = !value // value2 = false
Enter fullscreen mode Exit fullscreen mode

in progress........

Reference article: https://www.geeksforgeeks.org/unary-operators-cc/

Top comments (0)