Pointer arithmetic c++ In Hindi
C++ प्रोग्रामिंग लैंग्वेज में पॉइंटर अरिथमेटिक C++ यूजर को ऐरे डाटा टाइप या मेमोरी ब्लॉक में स्टोर एलिमेंट वैल्यू पॉइंटर्स पर ऑपरेशन करने में हेल्प करता है। पॉइंटर अरिथमेटिक C++ में लो-लेवल मेमोरी मैनेजमेंट फीचर्स के साथ काम करने, कॉन्टिनियस सीक्वेंस में ऐरे ब्लॉक डाटा एलिमेंट वैल्यू पर लूपिंग के माध्यम से इटरेट करने और प्रोग्राम में डिफाइन डेटा को प्रॉपर आर्डर में मैनिपुलेट करने के लिए एसेंशियल कांसेप्ट है।

So, let’s take a closer look at the key operational features of pointer arithmetic in C++ programming.
Pointer Arithmetic Operation Concepts in C++.
C++ प्रोग्रामिंग में किसी प्रोग्राम में पॉइंटर्स डाटा टाइप वेरिएबल के साथ C++ यूजर कई बेसिक ऑपरेशन या कंडीशन को परफॉर्म कर सकते हैं.
Common Pointer Arithmetic Operation in C++.
- पॉइंटर वेरिएबल एलिमेंट को बढ़ाना (pntr++)
- पॉइंटर पैरामीटर वैल्यू को घटाना (pntr–)
- पॉइंटर में एक इंटीजर वैल्यू को ऐड करना (pntr + n)
- पॉइंटर से एक इंटीजर वैल्यू को सब्ट्रैक्ट करना (pntr – n)
- दो पॉइंटर्स वैल्यू को सब्ट्रैक्ट करना (pntr1 – pntr2)
C++ यूजर हर पॉइंटर वेरिएबल ऑपरेशन पॉइंटर के डाटा टाइप (जैसे, यह किस तरह के डेटा टाइप वैल्यू एलिमेंट को इंडीकेट करता है) के आधार पर अलग-अलग पॉइंटर डाटा बिहैवियर ऑपरेशन को परफॉर्म करते है।
So, let’s look at pointer variable operations with some examples.
Incrementing and Decreasing Pointer Data Variables Operations.
जब C++ यूजर किसी प्रोग्राम में डिफाइन पॉइंटर वैल्यू एलिमेंट को इनक्रीस (pntr++) या डीक्रीज़ (pntr–) हैं. तो C++ यूजर इस कंडीशन में पॉइंटर को उस डाटा टाइप के नेक्स्ट या प्रीवियस वैल्यू एलिमेंट की ओर पॉइंट या इनक्रीस करने के लिए मॉडिफाई हो रहे हैं, जिसकी ओर वह एक्जैक्ट पॉइंट करता है।
Element of Incrementing and Decreasing Pointer Data Variables.
- pntr++ – यह मौजूदा प्रोगाम में पॉइंटर वैल्यू को उस डाटा टाइप के साइज़ से इनक्रीस करता है, जिसकी ओर वह पॉइंट करता है. (जैसे, अगर यह int* है, तो यह sizeof(int) से इसे मूव करता है)।
- pntr– – यह मौजूदा प्रोगाम में पॉइंटर वैल्यू को उस टाइप के साइज़ से डीक्रीज़ करता है, जिसकी ओर वह वेरिएबल वैल्यू को पॉइंट करता है।
Example of Incrementing and Decreasing Pointer Data Variables.
#include <iostream>
int main() {
int array[] = {89, 39, 82, 90, 11, 44};
int* pntr = array; // here we use pointer to the first element of the array
std::cout << “First array element value is – ” << *pntr << std::endl; // Result is – 89
pntr++; // here it move to the next array element (pointer points to array[1])
std::cout << “Next array element value is – ” << *pntr << std::endl; // Result is – 39
pntr–; // here it move back to the previous array element (pointer points to array[0])
std::cout << “Previous array element value is – ” << *pntr << std::endl; // Result is – 89
return 0;
}
Explanation of Incrementing and Decreasing Pointer Data Variables.
- यहाँ इस एक्साम्प्ल में, pntr++ पॉइंटर को नेक्स्ट ऐरे एलिमेंट (array[1]) लोकेशन पर मूव करता है।
- इसी तरह pntr– इसे प्रीवियस ऐरे एलिमेंट (array[0]) लोकेशन पर मूव करता जाता है।
Adding an integer to a pointer Operation Concepts in C++.
C++ यूजर किसी पॉइंटर प्रोग्राम में डिफाइन वैल्यू को n एलिमेंट से आगे फॉरवर्ड करने के लिए उसमें एक इंटीजर n वैल्यू के साथ ऐड कर सकते हैं। यह पॉइंटर डाटा मेमोरी में n पोजीशन पर मूव होगा, जहां यह हर स्टेप उस डाटा टाइप का साइज़ होगा, जिसकी ओर वह मौजूदा पॉइंटर वैल्यू को इंडीकेट करता है।
Example of adding an integer to a pointer operation.
#include <iostream>
int main() {
int array[] = {89, 39, 55, 61, 11, 44};
int* pntr = array; // here we define pointer to the first element of the above array
std::cout << “First array element value is – ” << *pntr << std::endl; // Result is – 89
pntr = pntr + 3; // here it move pointer 3 positions forward (to array[3] location)
std::cout << “Fourth array element value is – ” << *pntr << std::endl; // Result is – 61
return 0;
}
Explanation of adding an integer to a pointer operation.
- यहाँ इस एक्साम्प्ल में, pntr = pntr + 3 पॉइंटर को 3 पोजीशन पर मूव करता है, (array[3] स्टोरेज एड्रेस लोकेशन पर)।
Subtracting an Integer from a Pointer Operation Concepts in C++.
C++ यूजर किसी पॉइंटर प्रोग्राम में डिफाइन वैल्यू से एक इंटीजर वैल्यू n को घटा सकते हैं। यह न्यूमेरिक वैल्यू ऑपरेशन पॉइंटर को मेमोरी में n पोजीशन बैकवॉर्ड लोकेशन पर मूव करता है।
Example of subtracting an integer from a pointer.
#include <iostream>
int main() {
int array[] = {100, 39, 55, 61, 11, 399};
int* pntr = array + 5; // here we define pointer to the last element of the array (array[5])
std::cout << “Last array element value is – ” << *pntr << std::endl; // Result is – 399
pntr = pntr – 1; // here it move pointer 1 positions backward direction (to array[1] location)
std::cout << “Fourth array element value is – ” << *pntr << std::endl; // Result is – 11
return 0;
}
Explanation of subtracting an integer from a pointer.
- यहाँ इस एक्साम्प्ल में, pntr = pntr – 1 पॉइंटर को एक पोजीशन में बैकवर्ड मूव करता है, जिससे यह array[1] की ओर वैल्यू को पॉइंट करता है।
Subtracting two pointers Operation Concepts in C++.
जब C++ यूजर मौजूदा प्रोग्राम में दो पॉइंटर्स को आपस में सब्ट्रैक्ट करते हैं, तो आउटपुट रिजल्ट में उनके बीच ऐरे एलिमेंट्स नंबर्स में अंतर होता है, यहाँ ऐरे बाइट का अंतर नहीं होता है। इस ऑपरेशन को C++ में तभी परफॉर्म किया जा सकता है. जब दोनों यूजर डिफाइन पॉइंटर्स एक ही ऐरे या मेमोरी ब्लॉक के एलिमेंट्स की ओर इंडीकेट करते हों।
Syntax of subtracting two pointers.
pntrFirst – pntrSecond
यहाँ इस सिंटेक्स में pntrFirst और pntrSecond के बीच ऐरे एलिमेंट्स के नंबर्स को इंडीकेट करता है। आउटपुट रिजल्ट में ऐरे एलिमेंट्स के नंबर्स है, ये बाइट के नंबर्स नहीं है।
Example of subtracting two pointers.
#include <iostream>
int main() {
int array[] = {100, 39, 55, 61, 11, 399};
int* pntrFirst = &array[1]; // here we define pointer to array[1] location
int* pntrSecond = &array[5]; // here we define pointer to array[5] location
// here we subtracting pointers gives the number of elements between them
std::cout << “Array element subtraction value is – ” << pntrSecond – pntrFirst << std::endl; // Result is – 4
return 0;
}
Explanation of subtracting two pointers.
- यहाँ इस एक्साम्प्ल में, pntrSecond और pntrFirst के बीच का डिफ्रेंस 4 है. क्योंकि array[1] और array[4] के बीच 3 एलिमेंट्स हैं।
Pointer Arithmetic Operation Concepts with Arrays in C++.
ऐरे डाटा टाइप एलिमेंट के साथ काम करते समय पॉइंटर अरिथमेटिक स्पेशली यूज़ किए जाते है, क्योंकि इस कंडीशन में ऐरे का नाम रियल में पहले एलिमेंट का पॉइंटर होता है। C++ यूजर ऐरे डाटा एलिमेंट में नेविगेट करने के लिए पॉइंटर अरिथमेटिक कांसेप्ट का यूज़ कर सकते हैं।
Example of Pointer Arithmetic Operation.
#include <iostream>
int main() {
int array[] = {89, 39, 55, 61, 11, 44};
int* pntr = array; // here we define pointer to the first element of the array
// here we using pointer arithmetic to iterate through the complete array element
for (int p = 0; p < 6; p++) {
std::cout << “The element of array ” << p + 1 << ” – ” << *(pntr + p) << std::endl;
}
return 0;
}
Explanation of Pointer Arithmetic Operation.
- यहाँ इस एक्साम्प्ल में, pntr + p पॉइंटर p एलिमेंट्स को फॉरवर्ड करता है, और *(pntr + p) रिलेटेड ऐरे एलिमेंट की वैल्यू को एक्सेस और डिस्प्ले करता है।
Pointer Arithmetic and Multidimensional Array Concepts in C++.
C++ प्रोग्रामिंग में पॉइंटर अरिथमेटिक ऐरे का यूज़ मल्टीडायमेंशनल ऐरे में एलिमेंट्स को एक्सेस और मैनेज करने में भी किया जा सकता है। C++ में एक मल्टीडायमेंशनल ऐरे रियल में ऐरे का एक ऐरे टेबल मैट्रिक्स डाटा ब्लॉक होता है, और पॉइंटर अरिथमेटिक को अलग-अलग मल्टीडायमेंशनल ऐरे पर अप्लाई किया जा सकता है।
Example of Pointer Arithmetic and (2D Array) Multidimensional Array.
#include <iostream>
int main() {
int array[4][4] = {
{9, 1, 6, 5},
{7, 8, 3, 2},
{1, 4, 3, 9}
};
int* pntr = &array[0][0]; // here we define pointer to the first element of the 2D multi-dimensional array
// here we accessing elements in the 2D array using pointer arithmetic operation
for (int p = 0; p < 12; p++) {
std::cout << *(pntr + p) << ” “; // here we print each 2D multi-dimensional array element
if ((p + 1) % 4 == 0) std::cout << std::endl; // here we add a newline after each array row
}
return 0;
}
Explanation of Pointer Arithmetic and (2D Array) Multidimensional Array.
- यहाँ इस एक्साम्प्ल में, pntr + p एक 2D ऐरे के एलिमेंट्स को एक्सेस और डिस्प्ले करता है (एक सिंगल पॉइंटर में फ़्लैट किया हुआ)। जैसा की array एक 2D ऐरे है, फिर भी पॉइंटर अरिथमेटिक इसे 1D ऐरे के रूप में डिस्प्ले करता है, एलिमेंट्स को रो-बाय-रो करके प्रीव्यू करता है।
Detail summary of pointer arithmetic with array
| Pointer Operation | Pointer Arithmetic Description | Detail Example |
| pntr++ | Increment operator used to move pointer to the next element of the type in index location | pntr++ |
| pntr– | Decrement operator used to move pointer to the previous element of the type | pntr– |
| pnt + n | Here It used to move pointer n positions forward direction (array elements) | pntr + 2 |
| pntr – n | Here It used to move pointer n positions backward direction (array elements) | pntr – 2 |
| pntr1 – pntr2 | Here It used to get the difference between two pointers variable (in elements) | pntr 2 – pntr1 |

