Header Ads

ad728
  • New Updates

    Accessing the Address of the Variable


     

    Accessing the Address of the Variable

    Pointer Variable Declare करने के बाद हमें उस Pointer Variable में उस Variable का Address Store करना पड़ता है , जिसे Pointer द्वारा Access करना है | यहां हम char प्रकार के Variable (character) में Stored अक्षर को Output में Print करना चाहते हैं |

    इसलिए Pointer Variable , ptr में हमें Variable (character) का Address Store करना होगा | हम जानते हैं कि & एक Address Operator है | इसे सामान्य तौर पर Address of the Variable भी कहा जा सकता है | यानी जब किसी Variable में कोई मान Store करना होता है , तब हम & के बाद उस  Variable का नाम लिखते हैं , जिसमें कोई मान Store  करना है | जैसे निम्न Statements देखें

    
    int num;
    

    यदि हमें इस num में कोई मान Store करना हो तो हम

    
    scanf(“%d”,&num);
    

    लिखते हैं , ये  Statement “C” Compiler को बताता है कि Keyboard से Input होने वाले मान को memory के उस Storage Cell में ले जाकर Store कर दो जिसका नाम num Declare किया गया है | यानी & Input होने वाले मान के Store होने की Location या Address compiler को बताता है |

    माना num नाम का Variable Memory में जिस Storage Cell में Store होता है उस Storage Cell का Address 2005 है , तो & Operator “C” Compiler को Inputted मान को Storage Cell 2005 का Address प्रदान करता है और Inputted मान इस Memory Location पर Store हो जाता है, जिसका नाम  num Declare किया गया है | इसी & Operator का प्रयोग करके हम एक Pointer Variable में किसी Variable की Storage Cell का Address Store कर सकते हैं |

    यही प्रक्रिया यहां  char प्रकार के Variable (character) का Address Pointer Variable ptr में Store हो जाता है | ये बात हमेंशा ध्यान रखें कि हम किसी भी Variable का Address उसी  Variable में Store कर सकते हैं जिसे Pointer प्रकार का Variable Declare किया गया हो | इसलिए Address Initialization से पहले Variable का Pointer प्रकार का Declare होना जरुरी होता है |

    यदि हम कोई Variable Declare करने के बाद केवल ये जानना चाहते हैं , कि वह  Variable किस Address पर Store हुआ है और उस Address को किसी Pointer Variable में Store करना नहीं चाहते तो हम %u Control String Use करना पड़ता है और उस Variable का Address पता करने के लिए & Operator का प्रयोग करना पड़ता है |

    जैसे हम ये जानना चाहते हैं कि हमने char प्रकार का जो Variable character Declare किया है , वह किस Memory Location या किस Address पर Store हुआ है तो निम्न Statement देना होगा

    
    printf(“The Address of Variable Character is %u”, &character);
    

    इस Statement में %u का प्रयोग इसलिए किया जाता है , क्योंकि कोई भी Memory Location हमेंशा एक बिना चिन्ह वाली संख्या होती है और हम किसी Storage Cell के साथ कोई Calculation नहीं कर सकते हैं | ये Statement Output के रूप में उस Storage Cell का Address print करता है , जिस Storage Cell में Character नाम का Variable Store होता है |

    No comments

    Post Top Ad

    ad728

    Post Bottom Ad

    ad728