🟡 Intermediate  ·  Lesson 24

Pointers – परिचय

Pointer क्या है?

Pointer एक variable है जो किसी दूसरे variable का memory address store करता है। Data value (जैसे 42) की बजाय, यह memory में उस location को hold करता है जहाँ value store है।

Concept
int x = 42;    // x value 42 store करता है, address 0x1234 पर
int *p = &x;   // p, x का ADDRESS (0x1234) store करता है
// *  = "pointer to int" declaration में
// &  = "address of x"

Pointers क्यों? ये allow करते हैं:

  • Pass by reference — दूसरे functions में variables modify करना
  • Dynamic memory — runtime पर memory allocate करना
  • Arrays — efficient manipulation
  • Data structures — linked lists, trees

Declare और Initialize

C Language
int   *ip;    // int pointer
float *fp;    // float pointer
int   *np = NULL; // NULL pointer — safe initialization

int age = 25;
int *ptr = &age;   // ptr age को point करता है
⚠️ Pointer हमेशा Initialize करें!

Uninitialized pointer random address contain करता है। Use करने पर crash! हमेशा NULL या valid address से initialize करें।

& और * Operators

C Language – Pointer Demo
int x = 42;
int *p = &x;

printf("x ki value   = %d\\n", x);   // 42
printf("x ka address = %p\\n", &x);  // 0x... (hex)
printf("p ki value   = %p\\n", p);   // Same as &x
printf("*p se value  = %d\\n", *p);  // 42 (dereference)
*p = 100;                           // Pointer se x change karo!
printf("x ab = %d\\n", x);           // x ab 100 hai!
x ki value = 42 x ka address = 0x7ffd5a1234 p ki value = 0x7ffd5a1234 *p se value = 42 x ab = 100

Pointer Arithmetic

Array को Pointer से Traverse करना
int arr[] = {10, 20, 30};
int *p = arr;   // पहले element को point करो
printf("%d\\n", *p);   // 10
p++;            // अगले int पर जाओ (+4 bytes)
printf("%d\\n", *p);   // 20

सारांश

  • Pointer किसी variable का memory address store करता है
  • Declare: int *p;
  • &variable — variable का address मिलता है
  • *pointer — address पर stored value मिलती है (dereference)
  • Use से पहले हमेशा initialize करें (NULL safe है)
  • Array name = first element का pointer
  • Functions में pointer pass करके variables modify करते हैं (pass by reference)
🏋️ Practice

Programs लिखें: (1) 5 variables के address और value print करें (2) Pointers से swap (3) Pointer arithmetic से array traverse (4) Function जो pointer के through min और max return करे।

अक्सर पूछे जाने वाले प्रश्न (FAQ)

C में pointer क्या है?
Pointer एक variable है जो किसी दूसरे variable का memory address रखता है, सीधे value नहीं। यह आपको data को अप्रत्यक्ष रूप से संदर्भित और बदलने देता है, और यह arrays, dynamic memory, और functions को data कुशलता से भेजने की नींव है।
C में pointer कैसे declare करते हैं?
आप declaration में नाम से पहले * लगाते हैं, जैसे int *p;, जिसका मतलब "p एक int का pointer है।" फिर आप इसे address-of operator से किसी variable पर point कराते हैं, जैसे p = &x;
pointers के साथ * और & operators क्या करते हैं?
& operator किसी variable का address देता है, तो &x वह है जहाँ x memory में रहता है। * operator pointer को dereference करता है, तो *p उस address की value पढ़ता या बदलता है जो pointer रखता है।
C में NULL pointer क्या है?
NULL pointer वह pointer है जो कहीं इशारा नहीं करता, NULL लिखा जाता है। यह दिखाने को इस्तेमाल होता है कि pointer अभी valid data पर नहीं है, और pointer dereference करने से पहले आपको हमेशा NULL जाँचना चाहिए।
C में pointers क्यों उपयोगी हैं?
Pointers functions को caller के variables बदलने देते हैं, dynamic memory allocation की अनुमति देते हैं, बड़े data को बिना copy किए भेजना कुशल बनाते हैं, और arrays, strings तथा linked lists जैसी data structures के पीछे का तंत्र हैं। ये C के काम करने के तरीके में केंद्रीय हैं।
← Back to C Tutorial
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।