Pointers to arrays, functions, and structures c++ In Hindi
C++ प्रोग्रामिंग लैंग्वेज में पॉइंटर्स डाटा टाइप वेरिएबल का अधिक यूज़ काम्प्लेक्स डाटा स्ट्रक्चर को रिप्रेजेंट करने में किया जा सकता है. जैसे कि ऐरे, फ़ंक्शन, और स्ट्रक्चर में डिक्लेअर डाटा टाइप वेरिएबल वैल्यू ऑब्जेक्ट को इंडीकेट करना। C++ में आपको पॉइंटर डाटा वैल्यू को इफेक्टिव मेमोरी मैनेजमेंट, डायनामिक डेटा स्ट्रक्चर, और लो-लेवल प्रोग्रामिंग के लिए इन कॉन्सेप्ट को समझना और जानना बहुत ज़रूरी है।

So, let’s explore pointers to array, function, and structure data types in C++ programming in detail.
Array Pointer Concept in C++.
C++ प्रोग्राम में एक यूजर डिफाइन पॉइंटर ऐरे के पहले एलिमेंट लोकेशन को इंडीकेट कर सकता है, और इसमें पॉइंटर अरिथमेटिक ऑपरेटर का यूज़ करके C++ यूजर ऐरे के अन्य एड्रेस एलिमेंट्स वैल्यू को एक्सेस कर सकते हैं।
Syntax of an Array Pointer.
किसी C++ प्रोग्राम में ऐरे डाटा टाइप एलिमेंट के लिए एक पॉइंटर वेरिएबल ऑब्जेक्ट डिक्लेयर करना।
DataType* pointerVariableName;
Array Pointer to point to an array.
pointerVariableName = array;
Example of Array Pointer in C++.
#include <iostream>
int main() {
int array[] = {98, 67, 15, 70, 95, 79}; // here we declare array of integers numbers
int* ptr = array; // Pointer to the first element of the array
// here we accessing array elements using the pointer data type
std::cout << “1st element of pointer to array – ” << *ptr << std::endl; // Result is – 98
std::cout << “2nd element of pointer to array – ” << *(ptr + 1) << std::endl; // Result is – 67
std::cout << “3rd element of pointer to array -” << *(ptr + 2) << std::endl; // Result is – 15
return 0;
}
Explanation of Array Pointer in C++.
- यहाँ ऐरे पॉइंटर में ptr ऐरे के पहले एलिमेंट (arr[0]) को इंडीकेट या पॉइंट करता है।
- पॉइंटर (ptr + 1) को इनक्रीस हो कर, हम नेक्स्ट ऐरे पॉइंटर एलिमेंट (arr[1]) पर मूव करते हैं, और इसी तरह आगे के सीक्वेंस में भी।
- ऐरे पॉइंटर में डीरेफरेंस ऑपरेटर (*) सिंबल का यूज़ उस मेमोरी लोकेशन पर वैल्यू को एक्सेस और मैनेज करने में किया जाता है. जिस डायरेक्शन में पॉइंटर उसे पॉइंट कर रहा है।
Important Notes of Array Pointer.
- C++ प्रोग्राम में एक ऐरे का नाम (जैसे, array) ऐरे के पहले एलिमेंट के पॉइंटर के बराबर होता है।
- जब किसी ऐरे को किसी यूजर डिफाइन फ़ंक्शन में पैरामीटर के साथ पास किया जाता है, तो इसमें रियल में पहले एलिमेंट को पॉइंटर में पास कर रहा होता है।
Pointer to Function Concept in C++.
C++ प्रोग्रामिंग में एक पॉइंटर डाटा टाइप वेरिएबल किसी यूजर डिफाइन फ़ंक्शन पैरामीटर वैल्यू को भी पॉइंट कर सकता है। इससे C++ यूजर किसी फ़ंक्शन को इनडायरेक्टली प्रोग्राम में कॉल कर सकते हैं. प्रोग्राम में डिक्लेअर मल्टीप्ल फ़ंक्शन पैरामीटर वैल्यू को आर्गुमेंट के रूप में पास कर सकते हैं, या यूजर डिफाइन फ़ंक्शन को किसी डेटा स्ट्रक्चर में स्टोर कर सकते हैं।
Pointer to Function Syntax.
किसी C++ प्रोग्राम में यूजर डिफाइन फ़ंक्शन पैरामीटर आर्गुमेंट के लिए पॉइंटर डाटा टाइप वेरिएबल को डिक्लेयर करना।
returnType (*pointerName)(parameterTypes);
Assigning a function to a pointer.
pointerName = &functionName;
Example of a Pointer to Function.
#include <iostream>
// here we define a simple function
int total(int p, int q) {
return p + q;
}
int subtract(int p, int q) {
return p – q;
}
int main() {
// here we declaring a pointer to a function that takes two integer value and returns an int data
int (*funcPointr)(int, int);
// here we assigning function addresses to the pointer data type
funcPointr = &total;
// here we calling the function through the pointer variable
std::cout << “The total is – ” << funcPointr(1, 4) << std::endl; // The total is – 5
// here we reassigning to it another function
funcPointr = &subtract;
// here we calling the second function through the pointer method
std::cout << “The subtraction is – ” << funcPointr(17, 9) << std::endl; // The subtraction is – 8
return 0;
}
Explanation of a Pointer to Function.
- यहाँ इस एक्साम्प्ल में int (*funcPointr)(int, int) एक पॉइंटर वेरिएबल funcPointr को एक फ़ंक्शन के लिए डिक्लेयर करता है. जो मौजूदा फंक्शन में दो int पैरामीटर वैल्यू आर्गुमेंट को इनपुट लेता है, और एक सिंगल आउटपुट में int वैल्यू को रिटर्न करता है।
- funcPointr = &total; पॉइंटर को total फ़ंक्शन का एड्रेस वैल्यू असाइन करता है।
- फ़ंक्शन को पॉइंटर के माध्यम से funcPointr(1, 4) सिंटैक्स का यूज़ करके कॉल किया जाता है।
Important Notes of Pointer to Function.
- C++ प्रोग्राम में यूजर डिफाइन फ़ंक्शन पॉइंटर को अन्य फ़ंक्शन में एक आर्गुमेंट के रूप में पास किया जा सकता है, जिससे इसमें कॉलबैक मैकेनिज़्म इनेबल हो जाते हैं।
- फ़ंक्शन पॉइंटर का यूज़ सिंपल डिस्पैच टेबल (फ़ंक्शन लुकअप टेबल) को इम्प्लीमेंट करने में भी किया जा सकता है।
Pointer to a Structure Concept in C++.
C++ प्रोग्रामिंग में स्ट्रक्चर डाटा टाइप के पॉइंटर डाटा टाइप C++ यूजर को स्ट्रक्चर डाटा टाइप एलिमेंट मेंबर के लिए डायनामिक आर्डर में मेमोरी को एलोकेट करने या किसी मौजूदा स्ट्रक्चर डाटा टाइप को रेफरेंस करने के फीचर्स प्रोवाइड करते हैं। C++ यूजर -> ऑपरेटर के यूज़ के साथ पॉइंटर का यूज़ करके स्ट्रक्चर मेंबर को एक्सेस और मैनेज कर सकते हैं. एक सामान्य C++ रेगुलर स्ट्रक्चर डाटा टाइप वेरिएबल के लिए . ऑपरेटर के बदले में इसे यूज़ करे।
Syntax of a Pointer to a Structure.
C++ प्रोग्राम में स्ट्रक्चर डाटा टाइप मेंबर एलिमेंट के लिए पॉइंटर डाटा टाइप वेरिएबल को डिक्लेयर करना।
struct SampleStruct* pointerVariableName;
Accessing its element members using the pointer data type.
pointerVariableName->memberName;
Example of a Pointer to a Structure.
#include <iostream>
struct Student {
std::string stu_name;
int stu_age;
};
int main() {
// here we declare a structure data member and a pointer to the structure data type
Student student = {“Siddhi Deora”, 23};
Student* ptr = &student; //here we define pointer to the structure data type
// here we accessing structure members using the pointer
std::cout << “Student Name is – ” << ptr->stu_name << std::endl; // Result is – Siddhi Deora
std::cout << “Student Age is – ” << ptr->stu_age << std::endl; // Result is – 23
// here another method, we using dereference operator and dot operator for structure member
std::cout << “Student Name (from dereferencing) method – ” << (*ptr).stu_name << std::endl; // Result is – Siddhi Deora
std::cout << “Student Age (from dereferencing) method – ” << (*ptr).stu_age << std::endl; // Result is – 23
return 0;
}
Explanation of a Pointer to a Structure.
- यहाँ इस एक्साम्प्ल में एक पॉइंटर ptr को स्टूडेंट स्ट्रक्चर की ओर पॉइंट करने के लिए इनिशियलाइज़ किया जाता है।
- स्ट्रक्चर के डाटा मेंबर्स को एक्सेस करने के लिए, हम ptr->memberName मेथड का यूज़ करते हैं। इसके अलावा, हम (*ptr).memberName मेथड का यूज़ करके पॉइंटर को डीरेफरेंस कर सकते हैं।
Important Notes of Pointer to a Structure.
- C++ प्रोग्राम में -> ऑपरेटर पॉइंटर टू स्ट्रक्चर मेंबर को डीरेफरेंस करने और फिर स्ट्रक्चर के मेंबर को एक्सेस और मैनेज करने का एक शॉर्टहैंड मेथड है। यदि C++ यूजर के पास किसी स्ट्रक्चर का पॉइंटर डाटा टाइप मेथड है, तो स्ट्रक्चर के मेंबर्स डाटा टाइप को एक्सेस करने के लिए -> स्ट्रक्चर टू पॉइंटर ऑपरेटर का यूज़ किया जाता है, जबकि यदि C++ यूजर के पास कोई स्ट्रक्चर वेरिएबल मेंबर है. तो आप . ऑपरेटर का यूज़ करके ऐसा कर सकते हैं।
Combining Pointers with Array, Function, and Structure Data Members.
C++ प्रोग्रामिंग में यूजर अधिक कॉम्प्लेक्स डेटा स्ट्रक्चर और एल्गोरिदम प्रोग्राम क्रिएट करने के लिए ऐरे, फंक्शन, और स्ट्रक्चर डाटा टाइप के पॉइंटर्स को आपस में ग्रुप कर सकते हैं। यहाँ हम C++ प्रोग्राम में ऐरे, फंक्शन, और स्ट्रक्चर डाटा टाइप के पॉइंटर्स कॉम्बिनेशन के एक्साम्प्ल को डिटेल में समझते हैं.
Example of an array of structure data members with pointers.
#include <iostream>
struct Student {
std::string stu_name;
std::string stu_course;
int course_fee;
};
int main() {
Student Students[] = {{“Siddhi”,”Java”, 1099}, {“Bhavishi”,”Python”, 1299}, {“Harry”,”Xcode”, 799}, {“Vivek”,”Ruby”, 899}};
Student* pntr = Students; // here pointer use to the first element in the array of structures member
for (int p = 0; p < 4; p++) {
std::cout << “Student Details ” << (p + 1) << ” – ” << pntr->stu_name << “, ” << pntr->stu_course << “, ” << pntr->course_fee << “, course fee.” << std::endl;
pntr++; // here it move to the next element in the array list
}
return 0;
}
Explanation of array of structure data members with pointers.
- यहाँ इस एक्साम्प्ल में, C++ यूजर स्ट्रक्चर डाटा टाइप के ऐरे में मूव करने के लिए पॉइंटर मेथड का यूज़ करते हैं। pntr पॉइंटर पहले एलिमेंट से स्टार्ट होता है, और हम हर स्ट्रक्चर डाटा के मेंबर को एक्सेस और मैनेज करने के लिए -> ऑपरेटर का यूज़ करते हैं।

