Accessing a Address Through It’s Pointer
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh5td8mnbkEbKWo2nXDOkLrMSCuaFutWBQ_YKDPzG42WtSiohw-ViI-6Ruc1pZtCWqt184_qCuoS3jM_jiJ57BO_1jb31OJsDfDvKyRkd7Tz_zDSm8f_nLQ4Wc4nlx3eFTXmjEst4rV-D5KMYnBFGQjp5prxJd66SMMCTE9dxnB21hZkaWFf655GpRe/w640-h480/Accessing%20a%20Address%20Through%20It%E2%80%99s%20Pointer.jpg)
Accessing a Address
Through It’s Pointer
Pointer Variable
Declare करके उस Pointer Variable को वांछित Variable
का Address Initialize करने के बाद , जब हमें Pointer
Variable को Access करना होता है , तब हमें *
Indirection Operator को use करना पड़ता है |
इसे
सामान्य तौर पर Value at the Address Operator भी कहा जाता है |
यानी किसी Pointer
Variable में Stored Address जिस Variable का है , उस Variable
का मान प्राप्त करने के लिए इस Operator का
प्रयोग किया जाता है | जैसे
ptr
में Character नाम के Variable का Address Stored है और हम ptr द्वारा character में store अक्षर
x को Output में Print करना चाहते हैं तो हमें निम्न Statement देना होगा –
printf(“\n Value At the Address %u of Variable character is %c “, ptr , *ptr);
यहां ptr
Output में Character की Storage Cell का Address Print करता है और *ptr Output में अक्षर Character नाम के Variable में Store अक्षर x को print
करता है | *ptr
“C” Compiler को ये बताता है कि Pointer Variable ptr में जिस Variable के Storage Cell का Address Store है ( यहां Pointer Variable
में Character के Storage Cell का Address Store है |
)
उस Address
पर जो मान स्थित है ( यहां अक्षर x Stored है
) उसे Output में Screen पर print
कर दो |
इस प्रकार से
किसी Pointer
Variable में स्थित Address जिस Variable
का हो उस Variable का मान Output में यदि Print करना हो तो हमें * Operator के साथ उस Pointer Variable को use करना पड़ता है | अब
हम एक उदाहरण देखते हैं जिसमें Address Operator & व Indirection Operator * को साथ में प्रयोग करके
कुछ Assignment किये गए हैं |
#include<stdio.h>
main()
{
char character ='x';
char *ptr;
char new1;
ptr = &character;
printf("\n Address of character is %u",&character);
printf("\n Address in Pointer Variable ptr is %u",ptr);
printf("\n Value in the character is %c",character);
printf("\n Value at the Address %u Stored is %c",ptr,*ptr);
new1 = *ptr;
printf("\n Value in the new1 is %c",new1);
}
Output
Address of character is 65535
Address in Pointer Variable ptr is 65535
Value in the character is x
Value at the Address 65535 Stored is x
Value in the new1 is x
इस Output
से स्पष्ट है कि Variable Character का Output 65535 है और &
Character Expression से Pointer Variable ptr में character का Address store हो गया है | इसलिए
दूसरे Output
में ptr में स्थित Address का मान भी 65535 है |
तीसरे
Output
में Character Variable में Stored अक्षर x को सामान्य तरीके से print किया गया है |
चौथे Output
में ये बताया गया है कि Pointer Variable ptr में
65535 Address Stored है |
(हमें
प्रथम Output
से पता है कि ये character नाम के variable की storage
cell का पता है | )
इस Address
पर अक्षर x Stored है |
इस
output
को *ptr Argument द्वारा Output में Print किया गया है , जो कि वास्तव में character
का ही मान print कर रहा है |
new1 = *ptr; Statement द्वारा new1 में Pointer Variable ptr में Stored Address के Variable क मान Assign किया गया है जो कि Character x है और इसे ही पांचवें Output
में print किया गया है |
इस प्रकार से &
जहां Address of the Variable बताता है यानी
कि कोई मान किस Address पर Stored है |
वहीं
*
Value at the Address बताता है यानी कि किसी Address पर क्या मान Stored है |
No comments