एक पॉइंटर एक वेरिएबल है जो दूसरे वेरिएबल का पता संग्रहीत करता है। पॉइंटर का डेटा प्रकार वेरिएबल के समान होता है।
इस पहेली में आपको उपयोग किए जा रहे पॉइंटर का आकार जानने की आवश्यकता है। पहेली पॉइंटर्स की समझ की जांच करती है जिससे आप वेरिएबल के आकार का अनुमान लगाते हैं।
int का आकार 4 बाइट्स होता है, जबकि int पॉइंटर का आकार 8 बाइट्स (64-बिट सिस्टम पर) होता है। आइए C++ में निम्नलिखित अभ्यास से अपने कौशल का परीक्षण करें।
उदाहरण
#include <iostream>
using namespace std;
int main() {
int a = 6;
int *p = &a;
int arr[5][8][3];
int *q = &arr[0][0][0];
int ans;
cout << "the value of a is " << a << endl;
cout << "predict the size of a ";
cin >> ans;
if(ans == sizeof(p))
cout << "Hurry! your prediction is right";
else
cout << "Your Guess is wrong";
cout << "Now try this " << endl;
cout << "arr is a 3D array" << endl;
cout << "predict the size of arr ";
cin >> ans;
if(ans == sizeof(q))
cout << "Hurry! your prediction is right";
else
cout << "Your Guess is wrong";
return 0;
}
आउटपुट
the value of a is 6 predict the size of a 8 Hurry! your prediction is right Now try this arr is a 3D array predict the size of arr 4 Your Guess is wrong