পয়েন্টার হলো এমন একটি ভেরিয়েবল যা অন্য একটি ভেরিয়েবলের অ্যাড্রেস স্টোর করে।
পয়েন্টারের বৈশিষ্ট্য
- পয়েন্টার মেমরি স্পেস বাঁচায়।
- পয়েন্টারের এক্সিকিউশন টাইম দ্রুত হয় কারণ সরাসরি মেমরি লোকেশন অ্যাক্সেস করে।
- পয়েন্টারের সাহায্যে মেমরি কার্যকরভাবে অ্যাক্সেস হয়, অর্থাৎ মেমরি ডাইনামিক্যালি অ্যালোকেট ও ডি-অ্যালোকেট হয়।
- পয়েন্টার ডেটা স্ট্রাকচারের সাথে ব্যবহৃত হয়।
পয়েন্টার ডিক্লেয়ারেশন
int *p;
এটি বোঝায় 'p' হলো একটি পয়েন্টার ভেরিয়েবল যা অন্য একটি ইন্টিজার ভেরিয়েবলের অ্যাড্রেস ধারণ করবে।
পয়েন্টার ইনিশিয়ালাইজেশন
অ্যাড্রেস অপারেটর (&) ব্যবহার করে পয়েন্টার ভেরিয়েবল ইনিশিয়ালাইজ করা হয়।
উদাহরণ:
int qty = 175; int *p; p = &qty;

পয়েন্টার দিয়ে ভেরিয়েবল অ্যাক্সেস
ভেরিয়েবলের মান অ্যাক্সেস করতে ইন্ডিরেকশন অপারেটর (*) ব্যবহার করা হয়।
প্রোগ্রাম
#include<stdio.h>
void main() {
// Declaring variables and pointer//
int a = 2;
int *p;
// Declaring relation between variable and pointer//
p = &a;
// Printing required example statements//
printf("Size of the integer is %d\n", sizeof(int)); // 4
printf("Address of %d is %d\n", a, p); // Address value
printf("Value of %d is %d\n", a, *p); // 2
printf("Value of next address location of %d is %d\n", a, *(p + 1)); // Garbage value from (p+1) address
printf("Address of next address location of %d is %d\n", a, (p + 1)); // Address value +4
// Typecasting the pointer//
// Initializing and declaring character data type//
// a=2 = 00000000 00000000 00000000 00000010
char *p0;
p0 = (char *)p;
// Printing required statements//
printf("Size of the character is %d\n", sizeof(char)); // 1
printf("Address of %d is %d\n", a, p0); // Address Value(p)
printf("Value of %d is %d\n", a, *p0); // First byte of value a - 2
printf("Value of next address location of %d is %d\n", a, *(p0 + 1)); // Second byte of value a - 0
printf("Address of next address location of %d is %d\n", a, (p0 + 1)); // Address value(p)+1
}
আউটপুট
Size of the integer is 4 Address of 2 is 6422028 Value of 2 is 2 Value of next address location of 2 is 10818512 Address of next address location of 2 is 6422032 Size of the character is 1 Address of 2 is 6422028 Value of 2 is 2 Value of next address location of 2 is 0 Address of next address location of 2 is 6422029