Introduction
C language में pointers सबसे powerful और important concepts में से एक हैं।
यह concept थोड़ा advanced है, लेकिन अगर सही से समझ लिया जाए तो programming बहुत आसान और efficient हो जाती है।
अब तक हमने variables के बारे में सीखा, जहाँ:
- variable value store करता है
लेकिन हर variable memory में store होता है और उसका एक address होता है।
उदाहरण:
int a = 10;- यहाँ
aकी value = 10 - और उसका एक memory address भी होता है (जैसे 1000)
अब सवाल:
क्या हम उस address को भी store कर सकते हैं?
हाँ — इसके लिए Pointer का उपयोग होता है।
Pointer एक ऐसा variable होता है जो किसी दूसरे variable का address store करता है।
Pointers का उपयोग इन situations में होता है:
- memory management
- function calls (reference passing)
- arrays और structures handling
- dynamic memory allocation
Definition
Pointer एक variable होता है जो किसी अन्य variable का memory address store करता है।
Pointer Declaration
Syntax
data_type *pointer_name;
Example
int *p;
Explanation:
pएक pointer है- यह integer type variable का address store करेगा
Example 1: Basic Pointer Program
#include <stdio.h>
int main()
{
int a = 10;
int *p;
p = &a;
printf("Value of a = %d\n", a);
printf("Address of a = %p\n", &a);
printf("Pointer value = %p\n", p);
printf("Value using pointer = %d", *p);
return 0;
}
Output (address vary करेगा):
Value of a = 10
Address of a = 1000
Pointer value = 1000
Value using pointer = 10
Explanation:
&a→ address of ap→ address store करता है*p→ value access करता है
Important Operators
1. Address Operator (&)
variable का address देता है
&a
2. Dereference Operator (*)
pointer से value access करता है
*p
Example 2: Pointer with Modification
#include <stdio.h>
int main()
{
int a = 5;
int *p = &a;
*p = 20;
printf("%d", a);
return 0;
}
Output:
20
Explanation:
- pointer के through value change हुई
- original variable भी change हो गया
Example 3: Multiple Pointers
#include <stdio.h>
int main()
{
int a = 10;
int *p1 = &a;
int *p2 = &a;
printf("%d %d", *p1, *p2);
return 0;
}
Output:
10 10
Technical Understanding
- Pointer memory address store करता है
- pointer indirect access देता है
- memory efficient programming में useful है
Important Points
- Pointer declaration में
*use होता है &→ address देता है*→ value access करता है- Pointer और variable दोनों same memory को refer कर सकते हैं
Exam Points
- Output-based questions अक्सर आते हैं
- Pointer = address store करने वाला variable
&और*operators बहुत important हैं- pointer से value modify हो सकती है