Sunday, March 16.

Header Ads

Colorful+Black+Friday+Discount+Leaderboard+Ad

Pointer Increment and Scale Factor

Muscle+Inc.+%25282%2529

Pointer%20Increment%20and%20Scale%20Factor


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

Post Top Ad

Post Bottom Ad