সি প্রোগ্রামিং ভাষায়, পয়েন্টার টু পয়েন্টার বা ডাবল পয়েন্টার হলো একটি ভেরিয়েবল যা অন্য একটি পয়েন্টারের ঠিকানা ধারণ করে।
ডিক্লেয়ারেশন
পয়েন্টার টু পয়েন্টারের ডিক্লেয়ারেশন নিচে দেওয়া হলো −
datatype ** pointer_name;
উদাহরণস্বরূপ, int **p;
এখানে, p হলো একটি পয়েন্টার টু পয়েন্টার।
ইনিশিয়ালাইজেশন
ইনিশিয়ালাইজেশনের জন্য ‘&’ ব্যবহার করা হয়।
উদাহরণস্বরূপ,
int a = 10; int *p; int **q; p = &a;
অ্যাক্সেসিং
ইন্ডিরেকশন অপারেটর (*) অ্যাক্সেসের জন্য ব্যবহার করা হয়।
নমুনা প্রোগ্রাম
নিচে ডাবল পয়েন্টারের জন্য একটি সি প্রোগ্রাম দেওয়া হলো −
#include<stdio.h> main ( ){ int a = 10; int *p; int **q; p = &a; q = &p; printf("a =%d ",a); printf(" a value through pointer = %d", *p); printf(" a value through pointer to pointer = %d", **q); }আউটপুট
উপরোক্ত প্রোগ্রাম এক্সিকিউট করলে নিচের ফলাফল আসে −
a=10 a value through pointer = 10 a value through pointer to pointer = 10
উদাহরণ
এখন, পয়েন্টার টু পয়েন্টার সম্পর্ক দেখানোর আরেকটি সি প্রোগ্রাম বিবেচনা করুন।
#include<stdio.h> void main(){ //Declaring variables and pointers// int a=10; int *p; p=&a; int **q; q=&p; //Printing required O/p// printf("Value of a is %d\n",a);//10// printf("Address location of a is %d\n",p);//address of a// printf("Value of p which is address location of a is %d\n",*p);//10// printf("Address location of p is %d\n",q);//address of p// printf("Value at address location q(which is address location of p) is %d\n",*q);//address of a// printf("Value at address location p(which is address location of a) is %d\n",**q);//10// }আউটপুট
উপরোক্ত প্রোগ্রাম এক্সিকিউট করলে নিচের ফলাফল আসে −
Value of a is 10 Address location of a is 6422036 Value of p which is address location of a is 10 Address location of p is 6422024 Value at address location q(which is address location of p) is 6422036 Value at address location p(which is address location of a) is 10