Notes in Hindi

Address-of (&) Operator in Pointers in Hindi

/ BCA / Programming with C and CPP

Pointer Operators Explanation in Hindi

Address-of (&) Operator in Pointers in Hindi

What is Address-of Operator (&)?

Address-of Operator को C या C++ में & symbol से दर्शाया जाता है। इसका उपयोग किसी भी variable का memory address प्राप्त करने के लिए किया जाता है। जब भी आप किसी variable के पहले & लगाते हैं, तो वह उस variable का address return करता है।

Why is Address Important in Pointers?

किसी भी variable का address जानना इसीलिए ज़रूरी होता है क्योंकि Pointers उसी address पर काम करते हैं। Pointer एक ऐसा variable होता है जो किसी दूसरे variable के address को store करता है।

Example of & Operator

#include<stdio.h> int main() { int num = 10; printf("Address of num is %p", &num); return 0; }

ऊपर के program में हमने &num का प्रयोग किया है जिससे हमें num variable का address मिलेगा। %p का प्रयोग pointer या address print करने के लिए किया जाता है।

Use Cases of & Operator

  • Pointer variable को initialize करने के लिए
  • Functions में Call by Reference implement करने के लिए
  • Dynamic memory के साथ काम करने के लिए

Value-at (*) Dereference Operator in Hindi

What is Dereference (*) Operator?

* operator को Dereference Operator कहा जाता है। यह operator pointer के द्वारा जिस memory address को point किया जा रहा है, उसकी actual value को access करता है। यानी कि यह value-at-address देता है।

Why is * Used with Pointers?

Pointer सिर्फ किसी variable का address रखता है लेकिन हम जब उस address पर रखी value को access करना चाहते हैं तब * का प्रयोग करते हैं।

Example of * Operator

#include<stdio.h> int main() { int num = 20; int *ptr = # printf("Value of num is %d", *ptr); return 0; }

यहाँ ptr num का address रख रहा है और *ptr उस address पर रखी value को print कर रहा है यानी 20।

Use Cases of * Operator

  • Pointer द्वारा किसी variable की value को modify करना
  • Dynamic memory से data read/write करना
  • Function pointers में function call करना

Pointer Operators with Examples in Hindi

Common Pointer Operators

  • & : Address-of Operator
  • * : Dereference Operator

Example Demonstrating Both Operators

#include<stdio.h> int main() { int num = 50; int *ptr; ptr = # // Address-of Operator printf("Value using *ptr = %d", *ptr); // Dereference Operator return 0; }

इस code में &num से हम num का address ले रहे हैं और *ptr से उस address की value को print कर रहे हैं।

Pointer Operators के साथ Real-World Examples

  • Array traversal में pointer arithmetic करना
  • Linked list जैसे data structures में navigation करना
  • System-level programming में memory को control करना

Pointer के साथ Variables और Address Table

Variable Value Address Pointer *Pointer (Dereference)
num 100 0x61ff0c 0x61ff0c 100

Use of & and * Operators Together in Hindi

क्या & और * को साथ में Use किया जा सकता है?

हाँ, ये दोनों operators एक साथ commonly use होते हैं। जब pointer में address store करना होता है तो & का प्रयोग किया जाता है और उस pointer से value प्राप्त करने के लिए * का।

Real Example of & and * Together

#include<stdio.h> int main() { int x = 5; int *p = &x; // & Operator int y = *p; // * Operator printf("x = %d, y = %d", x, y); return 0; }

यहाँ हमने &x के ज़रिए x का address p में रखा और फिर *p के ज़रिए उस address की value y में assign की। यानी x और y दोनों की value 5 होगी।

Chained Example

#include<stdio.h> void update(int *ptr) { *ptr = *ptr + 10; } int main() { int a = 15; update(&a); // Passing address using & and modifying using * printf("Updated value = %d", a); return 0; }

इस code में हमने function को address pass किया है और उस address पर जाकर value को modify किया है यानी 15 से 25 कर दिया गया।

Important Points

  • & से हम किसी variable का address ले सकते हैं।
  • * से हम उस address की value प्राप्त कर सकते हैं।
  • *(&variable) = variable की value
  • &(*pointer) = वही original address

Pointer के उपयोग से क्या-क्या किया जा सकता है?

  • Memory को Directly access करना
  • Functions में Call by Reference करना
  • Complex Data Structures जैसे Linked List, Trees implement करना
  • Dynamic Memory Allocation

FAQs

& operator का उपयोग किसी भी variable का memory address प्राप्त करने के लिए किया जाता है। जब हम किसी variable के पहले & लगाते हैं, तो वह उस variable के address को pointer में assign करने के काम आता है।
* operator का उपयोग pointer द्वारा जिस memory address को point किया जा रहा है, उसकी actual value को access करने के लिए किया जाता है। इसे dereferencing कहते हैं।
हाँ, हम & और * operators को एक साथ उपयोग कर सकते हैं। & से हम address प्राप्त करते हैं और * से उस address की value को access करते हैं। यह pointer concept का core हिस्सा है।
किसी variable का address pointer में store करके उस pointer से value प्राप्त करने के लिए *ptr का उपयोग किया जाता है। यह उस address पर रखी value को देता है।
& operator किसी variable का address देता है जबकि * operator उस address की value को देता है। एक address प्राप्त करने के लिए होता है और दूसरा उस address को dereference करने के लिए।

Please Give Us Feedback