Pointer Increment and Scale Factor
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgzVq21BCyyX3ECg8L-2vudtK9KJNMjJqHVjZsHoNgCCtn4j0RZ_yLYlvG9NnA6UBFWmRYiEV9iyUYvklKcbRI-0zUgP6gz7gF_KWb_5z1qmxWSpHV5Y6iA66AfZb9T6Y2H6wmdJD6ViFojlo03uShJPCeqB9dWCyzSzpoHOo90oySISVaM_DitRvRR/w640-h480/Pointer%20Increment%20and%20Scale%20Factor.jpg)
Pointer Increment and
Scale Factor
जब Pointer
को Increase या Decrease करना होता है , तो ये सामान्य Variables की तरह Increase
या Decrease नहीं होते हैं |
जब Pointer को
Increase या Decrease किया जाता है तो
इनका Increment या Decrement इस बात पर
निर्भर करता है कि Pointer Variable किस प्रकार के Data
Type के Variable का Address ग्रहण करेगा |
जैसे int
प्रकार का Pointer दो byte की space Reserve करता है इसलिए यदि इस Pointer
Variable को Increase या Decrease किया जाए , तो Pointer में स्थित Address दो – दो के क्रम में बढ़ेगा या घटेगा |
इसी प्रकार यदि char
प्रकार का Pointer हो तो वह एक – एक क्रम में
बढ़ेगा या घटेगा | यदि
Pointer
Variable में किसी double प्रकार के Data
Type का Address Store है , तो इस Variable
को Increase या Decrease करने पर Pointer में Store Address आठ – आठ Byte के क्रम में Increase या Decrease होगा |
इसे
Pointer
का Scale Factor कहते हैं |
Scale Factor को निम्नानुसार एक प्रोग्राम द्वारा समझने की कोशिश करते हैं |
इस
प्रोग्राम के Output में आप देख सकते हैं कि ch
एक char प्रकार का Variable है और इसका Address Increase करने पर ये एक – एक के
क्रम में बढ़ता है क्योंकि char प्रकार का Variable
Memory में एक Byte लेता है |
जबकि int
प्रकार के Variable का Address दो – दो के क्रम में Increase हो रहा है और float
प्रकार के Data Type के Variable का Address चार Byte के क्रम
में Increase हो रहा है क्योंकि float प्रकार
का Data Memory में चार Byte की Space
लेता है |
Program
#include<stdio.h>
main()
{
char ch, *chp=&ch;
int num, *nump=#
float digit, *digitp=&digit;
printf("\n Address of ch is%u ",chp);
chp++;
printf("\n After Increasing the Address of ch is%u ",chp);
chp++;
printf("\n After Increasing the Address of ch is%u ",chp);
printf("\n \n Address of integer num is%u ",nump);
nump++;
printf("\n After Increasing the Address of integer num is%u ",nump);
nump++;
printf("\n After Increasing again Address of integer num is%u ",nump);
printf("\n \n Address of float digit is %u ",digitp);
digitp++;
printf("\n After Increasing the Address of float digit is%u ",digitp);
digitp++;
printf("\n After Increasing again Address of float digit:%u ",digitp);
getch();
}
Output
Address of ch is65525
After Increasing the Address of ch is65526
After Increasing the Address of ch is65527
Address of integer num is65522
After Increasing the Address of integer num is65524
After Increasing again Address of integer num is65526
Address of float digit is 65518
After Increasing the Address of float digit is65522
After Increasing again Address of float digit:65526
No comments