पॉइंटर एक वेरिएबल है जो दूसरे वेरिएबल का एड्रेस स्टोर करता है।
पॉइंटर्स की विशेषताएं
पॉइंटर मेमोरी स्पेस बचाता है।
मेमोरी लोकेशन तक सीधी पहुंच के कारण पॉइंटर का एक्जीक्यूशन टाइम तेज होता है।
पॉइंटर्स की मदद से मेमोरी को कुशलतापूर्वक एक्सेस किया जाता है, यानी मेमोरी डायनामिकली एलोकेट और डीएलोकेट होती है।
पॉइंटर्स का उपयोग डेटा स्ट्रक्चर्स के साथ किया जाता है।
पॉइंटर घोषित करना
int *p;
इसका मतलब है 'p' एक पॉइंटर वेरिएबल है जो दूसरे इंटीजर वेरिएबल का एड्रेस रखता है।
पॉइंटर का इनिशियलाइज़ेशन
एड्रेस ऑपरेटर (&) का उपयोग पॉइंटर वेरिएबल को इनिशियलाइज़ करने के लिए किया जाता है।
उदाहरण के लिए,
int qty = 175; int *p; p = &qty;

पॉइंटर के माध्यम से वेरिएबल एक्सेस करना
वेरिएबल के मान को एक्सेस करने के लिए, इंडायरेक्शन ऑपरेटर (*) का उपयोग किया जाता है।
प्रोग्राम
#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)); // (p+1) एड्रेस से गार्बेज वैल्यू //
printf("Address of next address location of %d is %d\n", a, (p+1)); // एड्रेस वैल्यू +4 //
// पॉइंटर टाइपकास्ट करना //
// कैरेक्टर डेटा टाइप इनिशियलाइज़ और घोषित करना //
// a = 2 = 00000000 00000000 00000000 00000010 //
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); // एड्रेस वैल्यू (p) //
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)); // वैल्यू a का दूसरा बाइट - 0 //
printf("Address of next address location of %d is %d\n", a, (p0+1)); // एड्रेस वैल्यू (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