Pointer to Pointer in C in Hindi
जैसा कि हम जानते हैं कि, C. पॉइंटर में एक वेरिएबल के पते को स्टोर करने के लिए एक पॉइंटर का उपयोग किया जाता है। हालाँकि, C में, हम एक पॉइंटर को दूसरे पॉइंटर के पते को स्टोर करने के लिए भी परिभाषित कर सकते हैं। ऐसे पॉइंटर को डबल पॉइंटर (पॉइंटर टू पॉइंटर) के रूप में जाना जाता है। पहले पॉइंटर का उपयोग वेरिएबल के address को स्टोर करने के लिए किया जाता है जबकि दूसरे पॉइंटर का इस्तेमाल पहले पॉइंटर के address को स्टोर करने के लिए किया जाता है। आइए इसे नीचे दिए गए diagram द्वारा समझते हैं।
डबल पॉइंटर घोषित करने का सिंटैक्स नीचे दिया गया है।
- int **p; // pointer to a pointer which is pointing to an integer.
निम्नलिखित उदाहरण पर विचार करें।
#include<stdio.h>
void main ()
{
int a = 10;
int *p;
int **pp;
p = &a; // pointer p is pointing to the address of a
pp = &p; // pointer pp is a double pointer pointing to the address of pointer p
printf("address of a: %x\n",p); // Address of a will be printed
printf("address of p: %x\n",pp); // Address of p will be printed
printf("value stored at p: %d\n",*p); // value stoted at the address contained by p i.e. 10 will be printed
printf("value stored at pp: %d\n",**pp); // value stored at the address contained by the pointer stoyred at pp
}
Output
address of a: d26a8734
address of p: d26a8738
value stored at p: 10
value stored at pp: 10
C double pointer example
आइए एक उदाहरण देखें जहां एक पॉइंटर दूसरे पॉइंटर के पते पर point करता है।
जैसा कि आप उपरोक्त figure में देख सकते हैं, p2 में p (fff2) का पता है, और p में number variable (fff4) का पता है।
#include<stdio.h>
int main(){
int number=50;
int *p;//pointer to int
int **p2;//pointer to pointer
p=&number;//stores the address of number variable
p2=&p;
printf("Address of number variable is %x \n",&number);
printf("Address of p variable is %x \n",p);
printf("Value of *p variable is %d \n",*p);
printf("Address of p2 variable is %x \n",p2);
printf("Value of **p2 variable is %d \n",*p);
return 0;
}
Output
Address of number variable is fff4
Address of p variable is fff4
Value of *p variable is 50
Address of p2 variable is fff2
Value of **p variable is 50