Substraction One Pointer to another Pointer
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1UUV47ezeSP40XiSiJORbkp5_BkrRY4VVoQewQa7mwh9ITyBTyJpmhPAbH2YY6GcScaDB85tIT_eazUzxb6OzJEdy_Rx0bV4oGv2GSIxIpU6ikN2VboVZb7Dcizpud6hJbn_8EJadWn3ZD77EIqv1tKTNOCUJ8v1qndGed67CgaEG9rhOtIeadlpE/w640-h480/Substraction%20One%20Pointer%20to%20another%20Pointer.jpg)
Substraction One
Pointer to another Pointer
किसी Array
के दो Elements का Address यदि दो अलग – अलग Pointer Variables में Stored
हो तो हम इन्हें आपस में घटा सकते हैं |
एक
Pointer
में से दूसरे Pointer को घटाने पर प्राप्त
होने वाला मान प्रथम Element से दूसरे Element के बीच की दुरी Bytes में बताता है |
इसे
समझने के लिए निम्न उदाहरण देखिये :
#include<stdio.h>
main()
{
int j[4],*k ,*l;
k= &j[1];
l= &j[3];
printf("\n Address of j[1] is %u ",k);
printf("\n Address of j[3] is %u ",k);
printf("\n j[3]-j[1] = ",j-i);
getch();
}
Output
Address of j[1] is 65520
Address of j[3] is 65524
j[3]-j[1] = 2
इस उदाहरण में हम
देखते हैं कि j[i] का Address 65520 व j[3] का Address 65524 है |
j[3]
– j[1] करने पर 65524 – 65520 होना चाहिए |
लेकिन
ऐसा नहीं होता , और इसका मान 2 प्राप्त होता है |
ऐसा
इसलिए होता है , क्योंकि किसी Pointer में से जब उसी
Array के किसी अन्य Element के Pointer
को घटाया जाता है , तब प्राप्त होने वाला मान Address की आपस की गणना का मान नहीं होता है , बल्कि ये मान उन दोनों Address
के बीच की दुरी बताता है कि दूसरा Element प्रथम
Element से कितना दूर या कितनी Byte दूर
स्थित है | यहां j[3]
, j[1] से दो Byte की दुरी पर स्थित है |
क्योंकि
ये int
प्रकार का Array है और int Memory में दो Byte की Space लेता है |
No comments