পয়েন্টার হলো একটি ভেরিয়েবল যা অন্য ভেরিয়েবলের অ্যাড্রেস সংরক্ষণ করে।
সিনট্যাক্স
pointer = &variable;
উদাহরণ প্রোগ্রাম
#include<stdio.h>
void main() {
int a = 2;
int *p;
p = &a;
printf("Size of the integer is %d\n", sizeof(int)); // 4
printf("Address of %d is %d\n", a, p);
printf("Value of %d is %d\n", a, *p); // 2
printf("Value of next address location of %d is %d\n", a, *(p+1)); // গার্বেজ ভ্যালু
printf("Address of next address location of %d is %d\n", a, (p+1)); // অ্যাড্রেস + 4
// টাইপকাস্টিং পয়েন্টার
char *p0;
p0 = (char*)p;
printf("Size of the character is %d\n", sizeof(char)); // 1
printf("Address of %d is %d\n", a, p0);
printf("Value of %d is %d\n", a, *p0); // a-এর প্রথম বাইট - 2
printf("Value of next address location of %d is %d\n", a, *(p0+1)); // দ্বিতীয় বাইট - 0
printf("Address of next address location of %d is %d\n", a, (p0+1)); // অ্যাড্রেস + 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 463824 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