
Chapter 14: C Programming में Pointers (पॉइंटर्स)
📚 C Programming – पूरा कोर्स रोडमैप
⬅ पिछला Chapter: | वर्तमान Chapter: Pointers | अगला Chapter: ➡
Author: Er. Mujtaba Ansari
क्या आप जानना चाहते हैं कि C Programming में Memory Address के साथ कैसे काम किया जाता है? Pointers इसी का आसान तरीका हैं।
🌍 Real-Life Benefits
- 💾 Memory Management में मदद
- 🚀 Program Performance बेहतर करना
- 🔄 Data को Directly Modify करना
- 📋 Arrays और Strings के साथ काम
- 🧩 Linked List, Stack और Tree जैसी Data Structures बनाना
C Programming में Pointers क्या हैं?
Pointer C Programming का एक बहुत ही important topic है। शुरुआत में हो सकता है Pointer थोड़ा मुश्किल लग सकता है, लेकिन अगर हम इसे आसान तरीके से समझें तो यह काफी simple है।
सबसे पहले समझते हैं कि Computer की Memory में हमारे Variables की Values store होती हैं।
उदाहरण:
int x = 10;
यहाँ x के अंदर 10 store है।
अब अगर हमें x की Memory में मौजूद जगह यानी Memory Address को store करना हो, तो हम Pointer का उपयोग कर सकते हैं।
Pointer क्या है?
Pointer एक ऐसा Variable है जो किसी दूसरे Variable का Memory Address store करता है।
Normal Variable में Value store होती है, जबकि Pointer में उस Value का Address store होता है।

उदाहरण:
int x = 10;
int *p;
p = &x;
यहाँ:
xएक Integer Variable है।xमें10store है।&xसेxका Memory Address मिलता है।pएक Integer Pointer है।pमेंxका Memory Address store है।
आसान तरीके से:
x = 10
p
|
|------> x
10
इसलिए Pointer की simple definition है:
Pointer एक Variable है जो किसी दूसरे Variable का Memory Address store करता है।
C Programming में Pointers का उपयोग क्यों किया जाता है?
Pointers का उपयोग C Programming में बहुत जगह किया जाता है।

Pointers की मदद से हम:
- Variable की Value को बदल सकते हैं।
- किसी Variable की Value indirectly access कर सकते हैं।
- Strings के साथ काम कर सकते हैं।
- Function में Variable का Address भेज सकते हैं।
- Dynamic Memory Allocation कर सकते हैं।
- Arrays के साथ आसानी से काम कर सकते हैं।
- Structure के Members को access कर सकते हैं।
- Memory से जुड़े low-level काम कर सकते हैं।
- Linked List और Trees जैसी Data Structures बना सकते हैं।
इसलिए C Programming में Pointer एक बहुत important concept है।
Pointer Declaration क्या है?
Pointer Declaration का मतलब है C Programming में एक ऐसा Pointer Variable बनाना जो किसी specific Data Type के Memory Address को store कर सके।
Pointer को declare करने के लिए * symbol का उपयोग किया जाता है।
Syntax
data_type *pointer_name;
Example
int *p;
यहाँ p एक Pointer है जो int type के Variable का Address store कर सकता है।
कुछ और examples:
float *fp;
char *cp;
double *dp;
इनका मतलब:
fp→ Float Variable का Address store कर सकता है।cp→ Character Variable का Address store कर सकता है।dp→ Double Variable का Address store कर सकता है।
Important Note for YOU
सिर्फ Pointer declare करने से वह किसी Variable को point नहीं करने लगता।
उदाहरण:
int *p;
इस समय p declare हो गया है, लेकिन इसे किसी valid Variable का Address नहीं दिया गया है।
इसलिए इसे सीधे dereference नहीं करना चाहिए।
Address-of Operator & क्या है?
C Programming में & को Address-of Operator कहते हैं।
इसका काम किसी Variable का Memory Address प्राप्त करना है।
उदाहरण:
int x = 10;
printf("%p", (void *)&x);
यहाँ:
&x
का मतलब है:
x का Memory Address
हम इस Address को Pointer में store कर सकते हैं।
int x = 10;
int *p;
p = &x;
अब p में x का Address store है।
Dereference Operator * क्या है?
Pointer के साथ * का उपयोग करने पर इसे Dereference Operator कहते हैं।
Dereference का simple मतलब है:
Pointer जिस Variable को point कर रहा है, उसकी Value प्राप्त करना।
उदाहरण:
#include <stdio.h>
int main(void)
{
int x = 9;
int *p = &x;
printf("Value of x = %d\n", x);
printf("Value using pointer = %d\n", *p);
return 0;
}
Output
Value of x = 9
Value using pointer = 9
यहाँ:
p = &x;
से p में x का Address store हुआ।
और:
*p
से x की Value मिली।
इसलिए:
p → x का Address
*p → x की Value
& और * को एक साथ समझें
मान लीजिए:
int x = 9;
int *p = &x;
अब:
x → 9
&x → x का Address
p → x का Address
*p → 9
आसान शब्दों में:
x→ Value&x→ x का Addressp→ Address को store करता है*p→ उस Address पर मौजूद Value देता है
यही Pointer का सबसे basic concept है।
Pointer को Initialize कैसे करें?
Pointer को use करने से पहले उसे किसी valid Address से initialize करना चाहिए।
उदाहरण:
int x = 25;
int *p = &x;
अब p, x को point कर रहा है।
हम:
printf("%d", *p);
लिखकर x की Value प्राप्त कर सकते हैं।
Output
25
Wild Pointer क्या है?
ऐसा Pointer जिसे declare किया गया है लेकिन उसे कोई valid Address नहीं दिया गया है, उसे commonly Wild Pointer कहा जाता है।
उदाहरण:
int *p;
यहाँ Pointer declare हुआ है, लेकिन अभी यह किसी valid Variable को point नहीं कर रहा है।
ऐसा करना dangerous हो सकता है:
*p = 10;
क्योंकि Program किसी गलत Memory Location को access कर सकता है।
सही तरीका
int x = 10;
int *p = &x;
या अगर अभी Pointer को किसी Variable से connect नहीं करना है:
int *p = NULL;
NULL Pointer क्या है?
जब Pointer किसी valid Variable या Object को point नहीं कर रहा हो, तो हम उसे NULL कर सकते हैं।
उदाहरण:
int *p = NULL;
इसका मतलब है कि p अभी किसी valid object को point नहीं कर रहा है।
Pointer को use करने से पहले check कर सकते हैं:
if (p != NULL)
{
printf("%d", *p);
}
NULL Pointer को कभी भी dereference नहीं करना चाहिए।
Pointer की मदद से Variable की Value बदलना
Pointer की मदद से हम उस Variable की Value भी बदल सकते हैं जिसे Pointer point कर रहा है।
उदाहरण:
#include <stdio.h>
int main(void)
{
int x = 10;
int *p = &x;
printf("Before: %d\n", x);
*p = 25;
printf("After: %d\n", x);
return 0;
}
Output
Before: 10
After: 25
यहाँ:
*p = 25;
ने x की Value बदलकर 25 कर दी।
क्योंकि p, x को point कर रहा था।
Pointers और Functions
Pointers का उपयोग Functions के साथ भी बहुत किया जाता है।
Pointers की मदद से हम:
- Variable का Address Function को दे सकते हैं।
- Function के अंदर original Variable की Value बदल सकते हैं।
- जरूरत के अनुसार valid object का Pointer return कर सकते हैं।
Function में Pointer कैसे Pass करें?
जब हम किसी Variable का Address Function को देते हैं, तो Function Pointer के माध्यम से original Variable को बदल सकता है।
इसे अक्सर Call by Address कहा जाता है।
लेकिन एक important बात:
C में वास्तविक Call by Reference नहीं होता।
C में सभी arguments pass by value होते हैं।
जब हम Pointer pass करते हैं, तो Pointer की Value यानी Address की एक copy Function को मिलती है। उस Pointer के माध्यम से Function original Variable को modify कर सकता है।
Pointers की मदद से दो Numbers Swap करना
अब एक simple Program देखते हैं।
Write a Program Swap Two Numbers Using Pointers in C
#include <stdio.h>
void swap(int *p, int *q);
int main(void)
{
int a, b;
printf("Enter two numbers: ");
scanf("%d %d", &a, &b);
printf("Before swap: a = %d, b = %d\n", a, b);
swap(&a, &b);
printf("After swap: a = %d, b = %d\n", a, b);
return 0;
}
void swap(int *p, int *q)
{
int temp;
temp = *p;
*p = *q;
*q = temp;
}
Input
5 4
Output
Before swap: a = 5, b = 4
After swap: a = 4, b = 5
यहाँ:
swap(&a, &b);
से a और b के Addresses Function को दिए गए।
Function में:
*p
और:
*q
के माध्यम से original Variables की Values access की गईं।
Pointer और Function की मदद से Largest Number Find करना
हम Pointer को Function के return value के रूप में भी use कर सकते हैं, लेकिन Pointer जिस object को point कर रहा है उसकी lifetime valid होनी चाहिए।
Program: Write a Program to Find the Largest of Two Numbers Using Pointer in C
#include <stdio.h>
int *largest(int *p, int *q);
int main(void)
{
int a, b;
int *big;
printf("Enter two numbers: ");
scanf("%d %d", &a, &b);
big = largest(&a, &b);
printf("Largest number = %d\n", *big);
return 0;
}
int *largest(int *p, int *q)
{
if (*p > *q)
return p;
else
return q;
}
Input
5 9
Output
Largest number = 9
यहाँ Function उस Variable का Pointer return करता है जिसकी Value बड़ी है।
Important Point for YOU
Function से किसी local Variable का Address return नहीं करना चाहिए।
गलत example:
int *getValue(void)
{
int x = 10;
return &x;
}
यह गलत है क्योंकि x एक local Variable है और Function खत्म होने के बाद उसका lifetime खत्म हो जाता है।
Pointer और Structure
Pointers का उपयोग Structure के साथ भी किया जाता है।
उदाहरण:
struct Complex
{
int real;
int imag;
};
अब Structure Variable:
struct Complex c;
और Structure Pointer:
struct Complex *p = &c;
अब p, Structure Variable c को point करता है।
Arrow Operator -> क्या है?
जब Structure Pointer के माध्यम से Structure के Members को access करना हो, तब -> operator का उपयोग किया जाता है।
उदाहरण:
p->real
यह:
(*p).real
के बराबर है।
इसी तरह:
p->imag
का मतलब:
(*p).imag
है।
इसलिए Structure Pointer के साथ -> operator बहुत useful है।
Structure Pointer से दो Complex Numbers जोड़ना
Write a Program to Addition of Two Complex Numbers Using Structure Pointer in C
#include <stdio.h>
struct Complex
{
int real;
int imag;
};
int main(void)
{
struct Complex a, b, c;
struct Complex *p = &a;
struct Complex *q = &b;
struct Complex *r = &c;
printf("Enter real and imaginary parts of first number: ");
scanf("%d %d", &p->real, &p->imag);
printf("Enter real and imaginary parts of second number: ");
scanf("%d %d", &q->real, &q->imag);
r->real = p->real + q->real;
r->imag = p->imag + q->imag;
printf("Result = %d + %di\n", r->real, r->imag);
return 0;
}
इस Program में Structure Members को Pointer के माध्यम से access किया गया है।
Structure के अंदर Pointer
Structure के अंदर भी हम Pointer रख सकते हैं।
उदाहरण:
struct Student
{
int roll;
char name[20];
int *marks;
};
यहाँ marks एक Pointer है।
Example:
struct Student student;
int marks = 95;
student.marks = &marks;
अब:
*student.marks
से marks की Value प्राप्त की जा सकती है।
Complete Program: इस program में Structure के अंदर Pointer का उपयोग करके किसी Variable की value को access किया गया है।
#include <stdio.h>
struct Student
{
int roll;
char name[20];
int *marks;
};
int main(void)
{
struct Student student;
int marks = 95;
student.roll = 7;
student.marks = &marks;
printf("Roll = %d\n", student.roll);
printf("Marks = %d\n", *student.marks);
return 0;
}
Output
Roll = 7
Marks = 95
Pointer और Array
Pointers और Arrays का C Programming में बहुत close relationship है।
मान लीजिए:
int a[5] = {20, 8, 91, 12, 9};
Array का पहला element:
a[0]
है।
और पहले element का Address:
&a[0]
है।
अधिकांश expressions में Array का नाम उसके first element के Pointer में बदल जाता है।
इसलिए:
a
का उपयोग first element के Address की तरह किया जा सकता है।
हम लिख सकते हैं:
int *p = a;
या:
int *p = &a[0];
दोनों में p Array के पहले element को point करता है।
Important बात
कई बार beginners को बताया जाता है:
Array name एक Constant Pointer है।
यह केवल समझाने का आसान तरीका है। Technical रूप से Array और Pointer एक ही चीज नहीं हैं।
Array एक अलग प्रकार का object है।
अधिकांश expressions में Array का नाम first element के Pointer में decay हो जाता है।
इसलिए:
a = a + 1;
valid नहीं है।
लेकिन:
p = p + 1;
valid है, क्योंकि p एक Pointer Variable है।
Pointer से Array Elements Access करना
मान लीजिए:
int a[5] = {20, 8, 91, 12, 9};
int *p = a;
पहले element को हम कई तरीकों से access कर सकते हैं:
a[0]
*(a + 0)
p[0]
*(p + 0)
इन सभी से first element की Value मिलती है:
20
इसी तरह third element:
a[2]
p[2]
*(a + 2)
*(p + 2)
सभी third element यानी:
91
को access करते हैं।
Pointer Arithmetic क्या है?
Pointer पर कुछ Arithmetic Operations किए जा सकते हैं। इसे Pointer Arithmetic कहते हैं।
अगर:
int *p = a;
तो:
p + 1
Array के अगले int element की ओर point करेगा।
इसे ऐसे समझें:
p → a[0]
p + 1 → a[1]
p + 2 → a[2]
p + 3 → a[3]
p + 4 → a[4]
Pointer Arithmetic में 1 का मतलब केवल 1 byte आगे जाना नहीं होता।
Pointer जिस Data Type को point कर रहा है, उसके size के अनुसार Address आगे बढ़ता है।
*(p + i) और *p + i में Difference
Beginners के लिए यह बहुत important concept है।
मान लीजिए:
int a[5] = {20, 8, 91, 12, 9};
int *p = a;
अब:
*(p + 4)
का मतलब है:
Pointer को 4 elements आगे ले जाकर उस element की Value लेना।
इसकी Value होगी:
9
लेकिन:
*p + 4
का मतलब है:
पहले *p की Value लो और फिर उसमें 4 जोड़ो।
20 + 4 = 24
इसलिए:
*(p + 4) → 9
*p + 4 → 24
Parentheses का बहुत महत्व है।
Pointer की मदद से Array का Largest Element Find करना
C Programming में Pointer का उपयोग करके Array का सबसे बड़ा Element Find करना
#include <stdio.h>
int main(void)
{
int a[100];
int n;
int i;
int largest;
int *p;
printf("Enter array size: ");
scanf("%d", &n);
if (n <= 0 || n > 100)
{
printf("Invalid array size.\n");
return 1;
}
printf("Enter array elements: ");
for (i = 0; i < n; i++)
{
scanf("%d", &a[i]);
}
p = a;
largest = *p;
for (i = 1; i < n; i++)
{
if (*(p + i) > largest)
{
largest = *(p + i);
}
}
printf("Largest element = %d\n", largest);
return 0;
}
यहाँ:
p = a;
से Pointer Array के first element को point करता है।
और:
*(p + i)
की मदद से Array के अलग-अलग elements को access किया गया है।
Largest और Second Largest Element Using Pointer
हम Pointer की मदद से Array में सबसे बड़ी और दूसरी सबसे बड़ी अलग Value भी find कर सकते हैं।
#include <stdio.h>
#include <limits.h>
int main(void)
{
int a[100];
int n, i;
int largest = INT_MIN;
int secondLargest = INT_MIN;
int *p = a;
printf("Enter array size: ");
scanf("%d", &n);
if (n < 2 || n > 100)
{
printf("Array must contain at least two elements.\n");
return 1;
}
printf("Enter array elements: ");
for (i = 0; i < n; i++)
{
scanf("%d", &a[i]);
}
for (i = 0; i < n; i++)
{
if (*p > largest)
{
secondLargest = largest;
largest = *p;
}
else if (*p > secondLargest && *p < largest)
{
secondLargest = *p;
}
p++;
}
if (secondLargest == INT_MIN)
{
printf("No distinct second largest element exists.\n");
}
else
{
printf("Largest element = %d\n", largest);
printf("Second largest element = %d\n", secondLargest);
}
return 0;
}
यहाँ:
p++;
से Pointer अगले Array element पर चला जाता है।
Pointer और String
C Programming में String Characters का एक sequence होता है, जिसके अंत में:
'\0'
Null Character होता है।
उदाहरण:
char city[10] = "Pune";
इसे conceptually ऐसे समझ सकते हैं:
P u n e \0
अब हम String के पहले Character को Pointer से point कर सकते हैं:
char *p = city;
अब:
printf("%s", p);
Output:
Pune
और:
printf("%c", p[2]);
Output:
n
Character Array और String Pointer में Difference
इन दोनों को ध्यान से समझें।
Character Array
char city[] = "Ranchi";
यह एक Character Array बनाता है।
इसके Characters को modify किया जा सकता है।
उदाहरण:
city[0] = 'D';
यह valid है।
Pointer to String Literal
const char *city = "Ranchi";
यहाँ city एक String Literal को point कर रहा है।
इस String को Pointer के through modify नहीं करना चाहिए।
const यह बताता है कि pointed Characters को बदलने का इरादा नहीं है।
Strings के लिए Array of Pointers
हम कई Strings के Addresses को एक Array में store कर सकते हैं।
उदाहरण:
const char *city[] =
{
"Garhwa",
"Delhi",
"Ranchi",
"Bangalore"
};
यहाँ:
city[0]
"Garhwa" को point करता है।
और:
city[1]
"Delhi" को point करता है।
Complete Program: C Programming में Array of Pointers का उपयोग करके City Names Print करना
#include <stdio.h>
int main(void)
{
const char *city[] =
{
"Garhwa",
"Delhi",
"Ranchi",
"Bangalore"
};
int i;
for (i = 0; i < 4; i++)
{
printf("%s\n", city[i]);
}
return 0;
}
Output
Garhwa
Delhi
Ranchi
Bangalore
Pointer to Pointer क्या है?
एक Pointer किसी दूसरे Pointer का Address भी store कर सकता है।
इसे Pointer to Pointer या Double Pointer कहते हैं।
उदाहरण:
int x = 10;
int *p = &x;
int **q = &p;
इसे ऐसे समझें:
q
↓
p
↓
x
↓
10
यहाँ:
x→ Value10रखता है।p→xका Address रखता है।q→pका Address रखता है।
अब:
*p
से x की Value मिलती है।
और:
**q
से भी x की Value मिलती है।
Pointer to Pointer का Program
C Programming में Double Pointer (Pointer to Pointer) का उपयोग
#include <stdio.h>
int main(void)
{
int x = 10;
int *p = &x;
int **q = &p;
printf("x = %d\n", x);
printf("*p = %d\n", *p);
printf("**q = %d\n", **q);
return 0;
}
Output
x = 10
*p = 10
**q = 10
Dynamic Memory Allocation और Pointers
Pointers का एक बहुत important use Dynamic Memory Allocation में होता है।
Dynamic Memory का मतलब है कि Program चलते समय जरूरत के अनुसार Memory लेना।
C में इसके लिए ये Functions उपयोग किए जाते हैं:
malloc()calloc()realloc()free()
इन Functions के लिए:
#include <stdlib.h>
include किया जाता है।
malloc() का उपयोग
malloc() का उपयोग
malloc() का उपयोग Runtime पर Dynamic Memory Allocate (Memory लेने) के लिए किया जाता है।
Syntax:
p = malloc(n * sizeof *p);
आसान शब्दों में: malloc() जरूरत के अनुसार Memory बनाता है, जिसे बाद में free() से Release किया जाता है।
Example: Write a Program Dynamic Memory Allocation using malloc() in C Programming
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int n;
int *p;
printf("Enter number of elements: ");
scanf("%d", &n);
if (n <= 0)
{
printf("Invalid number of elements.\n");
return 1;
}
p = malloc((size_t)n * sizeof *p);
if (p == NULL)
{
printf("Memory allocation failed.\n");
return 1;
}
for (int i = 0; i < n; i++)
{
p[i] = (i + 1) * 10;
}
for (int i = 0; i < n; i++)
{
printf("%d ", p[i]);
}
free(p);
return 0;
}
अगर Input है:
5
तो Output:
10 20 30 40 50
यहाँ:
malloc()
Runtime पर Memory allocate करता है।
काम पूरा होने के बाद:
free(p);
से allocated Memory release की जाती है।
malloc(), calloc(), realloc() और free()
malloc()
जरूरत के अनुसार Memory का एक block allocate करता है।
calloc()
कई elements के लिए Memory allocate करता है और allocated bytes को zero-initialize करता है।
realloc()
पहले से allocated Memory का size बदलने के लिए उपयोग होता है।
free()
Allocated Memory को वापस release करने के लिए उपयोग होता है।
C में Common Pointer Mistakes
Pointers के साथ छोटी गलती भी Program में problem पैदा कर सकती है। इसलिए इन mistakes से बचना चाहिए।
1. Uninitialized Pointer का उपयोग
गलत:
int *p;
*p = 10;
यहाँ p को कोई valid Address नहीं दिया गया है।
सही:
int x = 10;
int *p = &x;
2. NULL Pointer को Dereference करना
गलत:
int *p = NULL;
printf("%d", *p);
NULL Pointer को dereference नहीं करना चाहिए।
3. free() के बाद Memory को Access करना
गलत:
free(p);
printf("%d", *p);
free(p) के बाद उस allocated Memory को access नहीं करना चाहिए।
एक common practice:
free(p);
p = NULL;
4. Local Variable का Address Return करना
गलत:
int *getValue(void)
{
int x = 10;
return &x;
}
x local Variable है। Function समाप्त होने के बाद x का lifetime खत्म हो जाता है।
इसलिए उसका Address return नहीं करना चाहिए।
5. Array की सीमा से बाहर जाना
अगर:
int a[5];
तो valid indexes हैं:
0
1
2
3
4
इसलिए:
a[5]
valid Array element नहीं है।
Pointer के साथ भी Array की सीमा से बाहर access नहीं करना चाहिए।
Normal Variable और Pointer में Difference
| Feature | Normal Variable | Pointer |
|---|---|---|
| क्या store करता है? | Value | Address/Pointer Value |
| Example | int x = 10; | int *p = &x; |
| Value access | x | *p |
| Address | &x से मिलता है | p में store हो सकता है |
| Access | Direct | Indirect |
| मुख्य उपयोग | Data store करना | Address के माध्यम से Data access करना |
उदाहरण:
int x = 10;
int *p = &x;
यहाँ:
x → 10
p → x का Address
*p → 10
Important Pointer Operators
| Operator | नाम | काम |
|---|---|---|
& | Address-of Operator | Variable का Address प्राप्त करना |
* | Dereference Operator | Pointer से Value access करना |
-> | Arrow Operator | Structure Pointer से Member access करना |
Example
int x = 10;
int *p = &x;
यहाँ:
&x
→ x का Address
p
→ x का Address store करता है
*p
→ x की Value देता है
Important Array और Pointer Expressions
मान लीजिए:
int a[5] = {10, 20, 30, 40, 50};
int *p = a;
First element के लिए:
a[0]
*p
p[0]
*(p + 0)
सभी की Value:
10
Third element के लिए:
a[2]
p[2]
*(a + 2)
*(p + 2)
सभी की Value:
30
Pointers के Very Important Points
Pointer में इन बातों को जरूर याद रखें:
- Pointer में किसी object का Address store करने वाली Pointer Value रखी जा सकती है।
&से किसी Variable का Address प्राप्त किया जाता है।*से Pointer को dereference किया जाता है।- Pointer को use करने से पहले उसे valid Address से initialize करना चाहिए।
NULLPointer किसी valid object को point नहीं करता।- NULL Pointer को dereference नहीं करना चाहिए।
- Pointer की मदद से किसी Variable की Value बदली जा सकती है।
- Function में Pointer देने से original Variable को modify किया जा सकता है।
- Arrays और Pointers का C में बहुत close relationship है।
- Array और Pointer एक ही चीज नहीं हैं।
p[i]और*(p + i)equivalent तरीके हैं जबpसही element को point कर रहा हो।- Structure Pointer के साथ
->operator का उपयोग किया जाता है। **का उपयोग Pointer to Pointer के लिए किया जाता है।- Dynamic Memory Allocation में Pointers जरूरी होते हैं।
malloc(),calloc(),realloc()औरfree()important memory functions हैं।free()के बाद released Memory को access नहीं करना चाहिए।- Array की सीमा से बाहर Pointer के माध्यम से access नहीं करना चाहिए।
- गलत Pointer use करने से Program में undefined behavior हो सकता है।
Frequently Asked Questions (FAQs)
1. C Programming में Pointer क्या है?
Pointer एक Variable है जो किसी दूसरे Variable या Object के Memory Address को store कर सकता है।
2. & Operator का क्या काम है?
& को Address-of Operator कहते हैं। इसका उपयोग Variable का Memory Address प्राप्त करने के लिए किया जाता है।
उदाहरण:
int x = 10;
int *p = &x;
3. * Operator का क्या काम है?
Pointer के साथ * का उपयोग Dereference करने के लिए किया जाता है। इससे Pointer जिस object को point कर रहा है, उसकी Value access की जा सकती है।
उदाहरण:
*p
4. Wild Pointer क्या है?
ऐसा Pointer जिसे valid Address से initialize नहीं किया गया हो, उसे commonly Wild Pointer कहते हैं।
उदाहरण:
int *p;
5. NULL Pointer क्या है?
NULL Pointer ऐसा Pointer है जो किसी valid object को point नहीं करता।
उदाहरण:
int *p = NULL;
6. क्या C में Call by Reference होता है?
C में Arguments pass by value होते हैं। लेकिन Pointer pass करके Function original Variable को modify कर सकता है। इसे commonly Call by Address कहा जाता है।
7. Pointer Arithmetic क्या है?
Pointer पर + या - जैसी Operations करके Array के elements के बीच move करने को Pointer Arithmetic कहा जाता है।
उदाहरण:
p + 1
यह अगले appropriate element की ओर point कर सकता है।
8. Structure Pointer क्या है?
जो Pointer किसी Structure Variable का Address store करता है, उसे Structure Pointer कहते हैं।
उदाहरण:
struct Student s;
struct Student *p = &s;
9. -> Operator का उपयोग क्यों किया जाता है?
Structure Pointer के माध्यम से Structure Member को access करने के लिए -> operator का उपयोग किया जाता है।
उदाहरण:
p->roll
10. Pointers क्यों important हैं?
Pointers का उपयोग Functions, Arrays, Strings, Structures, Dynamic Memory और Linked Lists जैसी Data Structures में किया जाता है। इसलिए C Programming सीखने के लिए Pointer का concept बहुत important है।
Conclusion
Pointers C Programming का एक बहुत important concept है।
Pointer को समझने के लिए सबसे पहले केवल इन चार चीजों को समझें:
Variable
Memory Address
&
*
एक simple example:
int x = 10;
int *p = &x;
printf("%d", *p);
इसमें:
x → 10
&x → x का Address
p → x का Address
*p → x की Value
यही Pointer की basic working है।

मुजतबा अंसारी एक सॉफ्टवेयर इंजीनियर तथा The Tech Earth के संस्थापक (Founder) और CEO हैं। वे तकनीक, आर्टिफिशियल इंटेलिजेंस (AI), सॉफ्टवेयर, साइबर सुरक्षा, ब्लॉगिंग, हेल्थ टेक, एग्री टेक और डिजिटल ट्रेंड्स से जुड़े विषयों पर लेख लिखते हैं। उनका उद्देश्य पाठकों को नई तकनीकों और डिजिटल दुनिया की नवीनतम जानकारियों से अपडेट रखना है।
