Pointers Concept: Address-of Operator (&) and Dereference (*) Notes in Hindi & English : पॉइंटर्स की मूल अवधारणा: एड्रेस-ऑफ (&) और डिरेफरेंसिंग (*) और 20 महत्वपूर्ण MCQ प्रश्न (Rajasthan IT Exam)

Post a Comment

PGDCA, BCA, B-Tech, MCA, M-Tech, B.Sc computer science राजस्थान सूचना सहायक व कंप्यूटर शिक्षक विशेष नोट्स: इस अध्याय में हम Pointers Concept: Address-of Operator (&) and Dereference (*) (पॉइंटर्स की मूल अवधारणा: एड्रेस-ऑफ (&) और डिरेफरेंसिंग (*)) की संपूर्ण थ्योरी, मुख्य तकनीकी बिंदु, तुलनात्मक तालिका और विगत परीक्षाओं के पैटर्न पर आधारित 20 अति-महत्वपूर्ण बहुविकल्पीय प्रश्न (MCQs) विस्तृत हिंदी व अंग्रेजी व्याख्या सहित पढ़ेंगे।

Overview: A pointer in C is a variable holding the memory address of another object; the unary & (address-of) operator obtains an object's address, while * (dereference) reads or modifies the value at that address.

अध्याय सार: C में पॉइंटर एक वेरिएबल है जो किसी अन्य वेरिएबल का मेमोरी एड्रेस रखता है; एड्रेस-ऑफ (&) ऑपरेटर पता प्राप्त करता है और डिरेफरेंस (*) ऑपरेटर उस पते पर रखा मान पढ़ता या बदलता है।

Pointers Concept: Address-of Operator (&) and Dereference (*): Detailed Notes & Architecture (पॉइंटर्स की मूल अवधारणा: एड्रेस-ऑफ (&) और डिरेफरेंसिंग (*))

1. Pointer Declaration & Architecture-Dependent Size (पॉइंटर डिक्लेरेशन व सिस्टम-आधारित आकार)

[EN] A pointer variable is declared with an asterisk attached to the identifier: 'int *p;' declares p as a pointer to an int. Always remember a classic declaration trap: 'int *a, b;' declares a as a pointer (int *) and b as a plain integer (int)! Crucially, all data pointers (char *, int *, double *, void *) store a virtual memory address and therefore have the EXACT same size on a given machine: typically 4 bytes on 32-bit systems and 8 bytes on 64-bit systems, regardless of the pointed type's width.

[HI] पॉइंटर की घोषणा 'int *p;' के रूप में होती है। ध्यान रखने योग्य नियम: 'int *a, b;' लिखने पर केवल a पॉइंटर (int *) बनता है जबकि b सामान्य पूर्णांक (int) रहता है। एक ही कंप्यूटर आर्किटेक्चर पर सभी डेटा पॉइंटर्स (char *, int *, double *, void *) समान आकार के होते हैं—32-बिट सिस्टम पर 4 बाइट और 64-बिट सिस्टम पर 8 बाइट, चाहे वे कितने ही बड़े डेटा टाइप की ओर संकेत करें।

2. Address-of (&) and Dereference (*) Operators (एड्रेस-ऑफ (&) तथा डिरेफरेंस (*) ऑपरेटर्स)

[EN] The unary address-of operator '&' yields the memory address of an lvalue variable: '&x' has type int * when x is int. Note that '&' cannot be applied to literals (&5), temporary expressions (&(x + 1)), register variables, or struct bit-fields. The unary dereference (indirection) operator '*' accesses the object located at the stored address: '*p = 50;' modifies x indirectly through p. Applied together, '&' and '*' cancel as inverses: *&x evaluates to x. Pointer values are printed via %p cast to (void *).

[HI] यूनरी एड्रेस-ऑफ ऑपरेटर '&' किसी वेरिएबल का मेमोरी पता देता है; यह स्थिरांक (&5), एक्सप्रेशन (&(x+1)) या register वेरिएबल पर लागू नहीं हो सकता। डिरेफरेंस ऑपरेटर '*' उस पते पर मौजूद मान को पढ़ता या बदलता है (जैसे *p = 50;)। दोनों एक-दूसरे के विपरीत हैं (*&x == x)। एड्रेस प्रिंट करने के लिए printf में (void *) टाइपकास्ट के साथ %p स्पेसीफायर प्रयोग होता है।

3. Special Pointer Categories: NULL, void *, Wild & Dangling (विशेष पॉइंटर्स: NULL, void *, वाइल्ड व डैंगलिंग पॉइंटर)

[EN] An uninitialized local pointer holds a random address and is called a Wild Pointer—dereferencing it corrupts arbitrary RAM. Initialize safe pointers to NULL (e.g., int *p = NULL;); dereferencing NULL intentionally crashes cleanly (Segmentation Fault) rather than corrupting state. A generic pointer 'void *' can hold any data object's address without cast, but CANNOT be directly dereferenced without first casting to a concrete type (e.g., *(int *)vp). A Dangling Pointer continues holding an address after its target variable went out of scope or was freed.

[HI] बिना इनिशियलाइज किया गया लोकल पॉइंटर 'वाइल्ड पॉइंटर' (Wild Pointer) कहलाता है जो किसी अज्ञात पते पर जाता है। सुरक्षित शुरुआत के लिए 'NULL' सेट करें (NULL को डिरेफरेंस करने से Segfault आता है)। 'void *' एक जेनेरिक पॉइंटर है जो किसी भी टाइप का एड्रेस रख सकता है पर बिना टाइपकास्ट किए डिरेफरेंस नहीं हो सकता। नष्ट हो चुके या free() हो चुके ब्लॉक का पता रखने वाला पॉइंटर 'डैंगलिंग पॉइंटर' कहलाता है।

4. Double Pointers (**), const Combinations & Call-by-Reference (डबल पॉइंटर (**), const संयोजन व कॉल-बाय-रेफरेंस)

[EN] A pointer to a pointer (e.g., int **pp = &p;) stores the address of pointer p, enabling *pp to access p and **pp to access x; double pointers are essential when a function must alter a caller's pointer (such as inserting at the head of a linked list). Understand const placement carefully: 'const int *p' is a pointer to a constant int (cannot change *p, can change p), whereas 'int * const p' is a constant pointer (cannot change p, can change *p). Passing addresses (&a, &b) enables Call-by-Reference behavior in C.

[HI] डबल पॉइंटर (int **pp = &p;) दूसरे पॉइंटर p का पता रखता है; *pp से p तथा **pp से मूल मान x मिलता है। const का नियम समझें: 'const int *p' में मान (*p) नहीं बदल सकते पर पता (p) बदल सकते हैं, जबकि 'int * const p' में पता (p) स्थिर रहता है पर *p बदला जा सकता है। फंक्शन में &a व &b पास करके C में कॉल-बाय-रेफरेंस (जैसे swap) संभव होता है।

Syntax, Formula & Technical Example (Pointers Concept: Address-of Operator (&) and Dereference (*))

#include <stdio.h>

void swap(int *a, int *b) {
    int tmp = *a; *a = *b; *b = tmp; // Dereferences to mutate caller ints
}

int main(void) {
    int x = 10, y = 25;
    int *p = &x, **pp = &p;
    **pp = 40;                       // Updates x from 10 to 40
    swap(&x, &y);                    // x=25, y=40
    printf("x=%d y=%d ptrSize=%zu\n", x, y, sizeof(p));
    return 0;
}

Pointers Concept: Address-of Operator (&) and Dereference (*) Quick Reference & Comparison Table

Pointer ConceptC Technical BehaviorExam Critical Note
Address-of (&var)Returns memory address of lvalue varIllegal on literals, expressions, register vars
Dereference (*ptr)Accesses/modifies value at stored addressUB / Segfault if ptr is NULL or Wild
Generic Pointer (void *)Stores any object address without typecastMust cast (type *) before dereferencing
Pointer Size (sizeof(ptr))4 bytes (32-bit) or 8 bytes (64-bit) ABIIdentical across char *, int *, double *

Pointers Concept: Address-of Operator (&) and Dereference (*) Top 20 Bilingual MCQs with Answers

Q1. On a standard 64-bit Linux (LP64) system where sizeof(char) = 1 and sizeof(double) = 8, what are sizeof(char *) and sizeof(double *)?

(64-बिट Linux (LP64) सिस्टम पर जहाँ char = 1 व double = 8 बाइट का है, वहाँ sizeof(char *) व sizeof(double *) क्या होंगे?)

(A) Both are 8 bytes

(B) 1 byte and 8 bytes

(C) 4 bytes and 8 bytes

(D) 1 byte and 4 bytes

Correct Answer: (A)

[EN] All data pointers store a memory address of the CPU's virtual address width (8 bytes on 64-bit), regardless of base type.

[HI] सभी डेटा पॉइंटर CPU के वर्चुअल एड्रेस (64-बिट पर 8 बाइट) का मान रखते हैं, अतः डेटा टाइप से पॉइंटर का आकार नहीं बदलता।

Q2. In the declaration 'int *p, q;', what are the exact types of p and q?

(डिक्लेरेशन 'int *p, q;' में वेरिएबल p और q के सटीक डेटा टाइप क्या हैं?)

(A) p is int, while q is int *

(B) p is a pointer to int (int *), while q is a regular int

(C) Both p and q are int * pointers

(D) Syntax error

Correct Answer: (B)

[EN] The * binds solely to the identifier p, NOT the base type int; to make both pointers, write 'int *p, *q;'.

[HI] * केवल पहले नाम p से जुड़ता है, इसलिए p पॉइंटर है पर q एक साधारण पूर्णांक (int) है।

Q3. Which expression in C causes a compile-time error when applying the address-of (&) operator?

(C में इनमें से किस पर एड्रेस-ऑफ (&) ऑपरेटर लगाने पर कम्पाइल-टाइम एरर आता है?)

(A) &ptr (where ptr is int *)

(B) &(x + 1)

(C) &arr[0]

(D) &x (where x is auto int)

Correct Answer: (B)

[EN] & requires an addressable lvalue in memory; (x + 1) is a temporary rvalue expression with no memory location.

[HI] & ऑपरेटर केवल किसी मेमोरी वाले lvalue पर लगता है; (x + 1) एक अस्थायी मान (rvalue) है जिसका कोई एड्रेस नहीं होता।

Q4. What does the following code print: int a = 7; int *p = &a; *p = *p + 5; printf("%d", a);?

(कोड: int a = 7; int *p = &a; *p = *p + 5; printf("%d", a); क्या प्रिंट करेगा?)

(A) Address of a

(B) 7

(C) 5

(D) 12

Correct Answer: (D)

[EN] p holds &a, so *p accesses and overwrites a directly to 7 + 5 = 12.

[HI] p के पास a का एड्रेस होने से *p = *p + 5 सीधे a के मान को बदलकर 12 कर देता है।

Q5. What is a 'Wild Pointer' in C?

(C प्रोग्रामिंग में 'वाइल्ड पॉइंटर (Wild Pointer)' किसे कहते हैं?)

(A) A pointer pointing to a global const variable

(B) An uninitialized pointer containing a random/garbage memory address

(C) A pointer explicitly initialized to NULL

(D) A void * pointer

Correct Answer: (B)

[EN] A local pointer declared without an initializer (e.g., int *p;) holds garbage bits and points arbitrarily into memory.

[HI] बिना इनिशियलाइज किए घोषित किया गया पॉइंटर जिसमें कोई भी अनजान गार्बेज एड्रेस पड़ा हो, वाइल्ड पॉइंटर कहलाता है।

Q6. What happens if a program tries to dereference a NULL pointer (*p where p == NULL)?

(यदि कोई प्रोग्राम NULL पॉइंटर को डिरेफरेंस (*p जहाँ p == NULL) करने की कोशिश करे तो क्या होता है?)

(A) Compiler converts NULL into address 1

(B) Returns 0 safely

(C) Allocates a new integer automatically

(D) Undefined Behavior (typically crashes immediately with Segmentation Fault)

Correct Answer: (D)

[EN] Address 0 (NULL) is unmapped by the OS virtual memory system; reading or writing *NULL triggers a hardware fault / Segfault.

[HI] ऑपरेटिंग सिस्टम मेमोरी एड्रेस 0 को सुरक्षित रखता है; NULL पर *p करने से तुरंत Segmentation Fault क्रैश आता है।

Q7. How is a 'Dangling Pointer' created in C?

(C में 'डैंगलिंग पॉइंटर (Dangling Pointer)' कब बनता है?)

(A) When a pointer is initialized to NULL

(B) When a pointer points to a string literal

(C) When two pointers store the same valid address

(D) When memory pointed to by a pointer is freed (free()) or goes out of scope while the pointer still holds that old address

Correct Answer: (D)

[EN] After free(p) or function return from local variable, the memory is reclaimed, leaving p pointing to invalid stale memory.

[HI] जब किसी पॉइंटर द्वारा संदर्भित मेमोरी free() हो जाए या लोकल वेरिएबल नष्ट हो जाए पर पॉइंटर में पुराना पता बना रहे, तो वह डैंगलिंग पॉइंटर बनता है।

Q8. Why cannot you dereference a 'void *vp' directly by writing '*vp' in ISO C?

(ISO C में किसी 'void *vp' जेनेरिक पॉइंटर पर सीधे '*vp' लिखकर डिरेफरेंस क्यों नहीं किया जा सकता?)

(A) void * has size 0 bytes

(B) void * pointers reside in read-only memory

(C) The compiler does not know how many bytes or which data type format to read from void *

(D) void * can only hold NULL

Correct Answer: (C)

[EN] Because void is an incomplete type of unknown size, you must cast first, e.g., *(int *)vp.

[HI] void का कोई आकार या डेटा फॉर्मेट नहीं होता, इसलिए कंपाइलर नहीं जानता कि कितने बाइट पढ़ने हैं; पहले *(int *)vp जैसा कास्ट जरूरी है।

Q9. What does 'const int *p' restrict compared to 'int * const p'?

('int * const p' की तुलना में 'const int *p' किस पर प्रतिबंध लगाता है?)

(A) Neither allows reading *p

(B) const int *p forbids changing p, whereas int * const p forbids changing *p

(C) Both forbid changing both p and *p

(D) const int *p forbids modifying *p (pointed value), whereas int * const p forbids modifying p (stored address)

Correct Answer: (D)

[EN] Read declarations right-to-left: 'const int *p' is pointer to const int; 'int * const p' is const pointer to int.

[HI] दाएँ से बाएँ पढ़ें: const int *p में मान (*p) नहीं बदल सकते, जबकि int * const p में एड्रेस (p) नहीं बदल सकते।

Q10. Given 'int x = 15; int *p = &x; int **q = &p; **q = 30;', what is the value of x afterward?

(यदि 'int x = 15; int *p = &x; int **q = &p; **q = 30;' चलाया जाए, तो x का मान क्या हो जाएगा?)

(A) Address of p

(B) Compile error

(C) 15

(D) 30

Correct Answer: (D)

[EN] *q accesses p (&x), so **q accesses x directly and assigns 30 to x.

[HI] *q से p मिलता है और **q से x, अतः **q = 30 लिखने से x का मान 30 हो जाता है।

Q11. Which printf format specifier is defined by ISO C specifically for printing pointer addresses?

(ISO C में पॉइंटर का मेमोरी एड्रेस प्रिंट करने के लिए printf में कौन सा फॉर्मेट स्पेसीफायर उपयोग होता है?)

(A) %u

(B) %p

(C) %d

(D) %s

Correct Answer: (B)

[EN] %p formats a (void *) pointer address (typically printed in hexadecimal).

[HI] पॉइंटर एड्रेस प्रिंट करने के लिए मानक %p स्पेसीफायर (सामान्यतः (void *) कास्ट सहित) प्रयुक्त होता है।

Q12. What does the expression '*&x' evaluate to for any normal variable x?

(किसी सामान्य वेरिएबल x के लिए एक्सप्रेशन '*&x' का मान किसके बराबर होता है?)

(A) Compile-time syntax error

(B) Address of x

(C) Double the value of x

(D) The variable x itself (its value as an lvalue)

Correct Answer: (D)

[EN] &x gets x's address and * immediately dereferences that address back to x.

[HI] &x पहले पता निकालता है और * तुरंत उस पते का मान लौटाकर वापस x दे देता है।

Q13. Why must swap(int *a, int *b) receive pointers &x, &y rather than plain values x, y?

(swap(int *a, int *b) को x, y के सीधे मान के बजाय &x, &y एड्रेस क्यों पास करने पड़ते हैं?)

(A) Pointers make integer copying faster inside swap

(B) C cannot pass two integers without pointers

(C) swap cannot declare local temp variable without pointers

(D) C uses Pass-by-Value; pointers let swap dereference and mutate caller's original variables

Correct Answer: (D)

[EN] Passing x, y copies only local values inside swap(); passing &x, &y grants write access to main()'s memory.

[HI] C केवल Pass-by-Value पर चलता है; पते पास करने से swap() मुख्य फंक्शन के वास्तविक वेरिएबल बदल पाता है।

Q14. What happens if you assign an integer directly without cast: 'int *p = 1000;' in modern ISO C?

(आधुनिक ISO C में बिना टाइपकास्ट किए 'int *p = 1000;' लिखने पर क्या होता है?)

(A) p safely allocates memory at byte 1000

(B) p automatically stores the value 1000 at *p

(C) p sets itself to NULL

(D) Compiler emits an incompatible integer-to-pointer conversion warning/error (and dereferencing 1000 causes Segfault)

Correct Answer: (D)

[EN] Only integer constant 0 acts as a null pointer constant; arbitrary integers like 1000 are invalid addresses in virtual memory.

[HI] केवल 0 ही नल पॉइंटर माना जाता है; 1000 जैसा सीधा पूर्णांक देने पर कंपाइलर चेतावनी/एरर देता है।

Q15. Which statement is NOT true about pointers in C?

(C में पॉइंटर्स के बारे में इनमें से कौन सा कथन असत्य है?)

(A) Dereferencing an uninitialized wild pointer causes Undefined Behavior

(B) NULL pointer indicates the pointer currently points to no valid object

(C) A double pointer (int **) occupies twice as many bytes in RAM as a single pointer (int *)

(D) & extracts the address of an lvalue

Correct Answer: (C)

[EN] Every pointer—single (int *), double (int **), or triple (int ***)—stores one virtual address and has the exact same byte size (e.g., 8 bytes on 64-bit).

[HI] डबल पॉइंटर (int **) का आकार भी सिंगल पॉइंटर (int *) जितना ही (64-बिट पर 8 बाइट) होता है, दोगुना नहीं।

Q16. When is a double pointer (Node **head) necessary as a C function parameter?

(किसी C फंक्शन के पैरामीटर में डबल पॉइंटर (जैसे Node **head) की आवश्यकता कब पड़ती है?)

(A) Whenever allocating a local int variable

(B) Whenever modifying the fields inside the struct pointed by head

(C) When the function needs to modify which address the caller's pointer itself points to

(D) Whenever passing a 1D array of integers

Correct Answer: (C)

[EN] Passing Node *head only lets the callee alter fields inside *head; modifying head itself (e.g., inserting at front) requires Node **head.

[HI] यदि फंक्शन को कॉलर के पॉइंटर वेरिएबल (जैसे लिंक्ड लिस्ट का head) को ही बदलकर नया एड्रेस देना हो, तब Node **head आवश्यक होता है।

Q17. Within Pointers Concept: Address-of Operator (&) and Dereference (*), which pointer concept directly maps to: "Returns memory address of lvalue var"?

(Pointers Concept: Address-of Operator (&) and Dereference (*) में कौन सा Pointer Concept सीधे "Returns memory address of lvalue var" से संबंधित है?)

(A) Generic Pointer (void *)

(B) Address-of (&var)

(C) Dereference (*ptr)

(D) Pointer Size (sizeof(ptr))

Correct Answer: (B)

[EN] In Pointers Concept: Address-of Operator (&) and Dereference (*), 'Address-of (&var)' handles 'Returns memory address of lvalue var' (Illegal on literals, expressions, register vars).

[HI] Pointers Concept: Address-of Operator (&) and Dereference (*) में 'Address-of (&var)' का कार्य/विवरण 'Returns memory address of lvalue var' (Illegal on literals, expressions, register vars) है।

Q18. Which option accurately describes 'Dereference (*ptr)' in Pointers Concept: Address-of Operator (&) and Dereference (*)?

(Pointers Concept: Address-of Operator (&) and Dereference (*) के संदर्भ में 'Dereference (*ptr)' की सही विशेषता कौन सी है?)

(A) Accesses/modifies value at stored address

(B) Stores any object address without typecast

(C) Returns memory address of lvalue var

(D) 4 bytes (32-bit) or 8 bytes (64-bit) ABI

Correct Answer: (A)

[EN] 'Dereference (*ptr)' provides 'Accesses/modifies value at stored address' — key point: UB / Segfault if ptr is NULL or Wild.

[HI] 'Dereference (*ptr)' का मुख्य विवरण 'Accesses/modifies value at stored address' है (UB / Segfault if ptr is NULL or Wild)।

Q19. In Pointers Concept: Address-of Operator (&) and Dereference (*), identify the correct parameter for the specification: "Stores any object address without typecast".

(Pointers Concept: Address-of Operator (&) and Dereference (*) में "Stores any object address without typecast" विवरण किस विकल्प के लिए सही है?)

(A) Address-of (&var)

(B) Dereference (*ptr)

(C) Pointer Size (sizeof(ptr))

(D) Generic Pointer (void *)

Correct Answer: (D)

[EN] 'Generic Pointer (void *)' corresponds to 'Stores any object address without typecast' (Must cast (type *) before dereferencing).

[HI] 'Generic Pointer (void *)' का संबंध 'Stores any object address without typecast' (Must cast (type *) before dereferencing) से है।

Q20. Considering Pointers Concept: Address-of Operator (&) and Dereference (*), what key behavior defines 'Pointer Size (sizeof(ptr))'?

(Pointers Concept: Address-of Operator (&) and Dereference (*) में 'Pointer Size (sizeof(ptr))' की मुख्य भूमिका या मान क्या है?)

(A) Returns memory address of lvalue var

(B) Accesses/modifies value at stored address

(C) Stores any object address without typecast

(D) 4 bytes (32-bit) or 8 bytes (64-bit) ABI

Correct Answer: (D)

[EN] 'Pointer Size (sizeof(ptr))' represents '4 bytes (32-bit) or 8 bytes (64-bit) ABI' (Identical across char *, int *, double *).

[HI] 'Pointer Size (sizeof(ptr))' का अर्थ/मान '4 bytes (32-bit) or 8 bytes (64-bit) ABI' है (Identical across char *, int *, double *)।

Pointers Concept: Address-of Operator (&) and Dereference (*) — Exam FAQs

Q1: How do I prevent Dangling Pointers after calling free(ptr)?

free(ptr) कॉल करने के बाद डैंगलिंग पॉइंटर बनने से कैसे बचें?

[EN] Always set 'ptr = NULL;' immediately after 'free(ptr);'. Checking 'if (ptr != NULL)' before later use then reliably prevents double-free bugs and stale dereferences.

[HI] हमेशा 'free(ptr);' के तुरंत बाद 'ptr = NULL;' सेट कर दें, जिससे गलती से दोबारा free या उपयोग करने की संभावना खत्म हो जाती है।

Q2: Can a pointer hold the address of a function instead of a variable?

क्या कोई पॉइंटर वेरिएबल के बजाय किसी फंक्शन का एड्रेस भी रख सकता है?

[EN] Yes! A Function Pointer (e.g., int (*fp)(int, int) = &add;) holds the code entry address of a function in the .text segment, enabling callbacks like qsort() comparators.

[HI] हाँ! फंक्शन पॉइंटर (जैसे int (*fp)(int, int) = add;) फंक्शन के कोड का एड्रेस रखता है और qsort() जैसे कॉलबैक फंक्शनों में उपयोग होता है।

Q3: Does 'int *p = 0;' make p a valid pointer to address 0 or a NULL pointer?

क्या 'int *p = 0;' लिखने से p एक सामान्य एड्रेस बनता है या NULL पॉइंटर?

[EN] In C, an integer constant expression with value 0 in a pointer context is defined by the standard as a Null Pointer Constant, making 'int *p = 0;' identical to 'int *p = NULL;'.

[HI] C मानक में पॉइंटर संदर्भ में स्थिरांक 0 लिखना NULL पॉइंटर के बिल्कुल समतुल्य माना जाता है।

Related Posts

  • Loading related posts...

Post a Comment

Search Topic Notes & 20 MCQs (Hindi / English)