Unary Operators in C language

Introduction

Programming में कुछ ऐसे operations होते हैं जिनमें केवल एक ही variable या value पर operation किया जाता है।

C language में ऐसे operations को perform करने के लिए Unary Operators का उपयोग किया जाता है।

यह operators value को increase, decrease या modify करने के लिए बहुत उपयोगी होते हैं और loops तथा calculations में बार-बार इस्तेमाल होते हैं।

Definition

Unary Operators वे operators होते हैं जो केवल एक operand (variable या value) पर कार्य करते हैं।

Types of Unary Operators

OperatorMeaning
+ +Increment (value को 1 बढ़ाता है)
– –Decrement (value को 1 घटाता है)

Example

#include <stdio.h>
int main()
{
int a = 5;

a++; // increment
printf("%d\n", a); // 6

a--; // decrement
printf("%d\n", a); // 5

return 0;
}

Pre और Post Unary Operators

  1. Pre-Increment (++a)
    पहले value बढ़ती है, फिर use होती है
  2. Post-Increment (a++)
    पहले value use होती है, फिर बढ़ती है

Example (Pre vs Post)

int a = 5;
int x = ++a; // a = 6, x = 6
int y = a++; // y = 6, a = 7

Real World Example

मान लो आप सीढ़ियाँ चढ़ रहे हैं:

  • हर step पर आप 1 step आगे बढ़ते हैं → increment
  • अगर नीचे उतरते हैं → decrement

इसी तरह:

  • ++ → value बढ़ाता है
  • — → value घटाता है

Exam Points

  • Unary operator एक operand पर काम करता है
  • ++ और — सबसे common unary operators हैं
  • Pre और Post increment/decrement में difference important है
  • Loop control में इनका बहुत उपयोग होता है

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top