JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

हिंदी माध्यम नोट्स

Categories: c++ language in hindi

Address variable in c++ language , Address variable within Function , Reference variable in hindi

इससे पहले के article मे inline function को discuss किया गया है | inline function को function की जगह use किया जाता है | इससे प्रोग्राम की speed को बढ़ जाता है | अब इस article मे address variable को discuss करेगे |Address variable
c++ मे नए compund variable को add किया गया है | जिसे address variable कहते है | reference का नाम जो की alias की तरह कार्य करता है | उदहारण के लिए variable name का reference n है अतः name और n दोनों को ही variable use किया जा सकता है | जब किसी reference को  argument की तरह कार्य करता है तब function orginal data की जगह  इसकी copy को use किया जाता है |  reference variable को pointer variable की जगह use किया जाता है |

Creating Reference variable
C or C++ languagr मे  “&” operator को किसी operator के address को define किया जाता है | c++ language मे  किसी variable को ‘&’ से declare किया जाता है | तब इसे address variable कहते है | इस variable को address को define करने के लिए किया जाता जाता है | उदाहरन के लिए ‘a’ एक variable है और name एक address variable है |
int a =10 ;
int &name = a;
इस उदाहरन मे ‘&’ का variable के address को define नहीं करा रहा है | बल्कि ये address variable को define कर रहा है | जैसे char * : इस type से character type के pointer को define करा रहा है | इसी तरह int & : इस type से integer type के address variable को define करता है | reference declartion name और a को interechange करने की facility provide करवाता है | लेकिन दोनों variable एक ही memory address और value को contain करता है |
उदहारण के लिए :
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
using namespace std;
int n=101;
int &number= n;
cout<<“value of n : “<<n<<endl;
cout<<“value of number : “<<number<<endl;
number++;
cout<<“value of n : “<<n<<endl;
cout<<“value of number : “<<number<<endl;
cout<<“Address of n :”<<&n;
cout<<“Address of number :”<<&number;
getch();
}
इस उदाहरन मे number address variable नहीं  है | लेकिन number variable , integer type के address को define करता है | इसके अलावा  cout<<“Address of n :”<<&n; और cout<<“Address of number :”<<&number; मे use किये गया &n और &number address variable है | और n और number की value और address सामान होती है | जब number की value को increment किया जाता है | दोनों variable की value बढती है |  C language मे , address variable को use करना थोडा confuse होता है लेकिन c++ language मे इसे pointer variable को use किया जाता है | इसके लिए उदहारण निन्म है |
int n =10 ;
int &name = a;
int *num=&n;
इस उदाहरन मे , num और n दोनों एक ही variable है |  लेकिन name = n को use नहीं करा सकते है | लेकिन इसके लिए निन्म उदाहरन है :
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
using namespace std;
int n=101;
int &number= n;
cout<<“value of n : “<<n<<endl;
cout<<“value of number : “<<number<<endl;
int second = 12 ;
number = second ;
cout<<“value of second : “<<second<<endl;
cout<<“value of n  : “<<n<<endl;
cout<<“value of number  : “<<number<<endl;
cout<<“Address of second :”<<&n;
cout<<“Address of number :”<<&number;
getch();
}
इस उदहारण मे , number = second ; execute होता है | इसके second की value को number मे assign हो जाता है | लेकिन second और number का address value अलग अलग होता है | लेकिन number और second का address सामान है |

Address variable within Function
reference को function मे parameter की तरह use किया जाता है | जब किसी variable नाम को किसी variable से call किया जाता है |जब किसी reference को function मे pass किया जाता है इसे passing by reference कहते है | passing by reference method मे , called function से variable को calling function से access किया जाता है | इस method मे variable के copy को use किया जाता है | function को तीन method से call किया जाता है |
call by value : value को function मे pass किया जाता है |
call by address  : address और pointer variable  को function मे pass किया जाता है |
call by reference : reference variable  को function मे pass किया जाता है |

इसका उदाहरन निन्म है :
#include<iostream.h>
#include<conio.h>
void swapreference(int & a , int & b );
void swappointer(int *p , int *q);
void swapvalue(int a , int b );
void main()
{
int value1 = 100;
int value2 = 200;
cout<<“Value1 :”<<value1;
cout<<“value 2 : “<< value2 ;
cout<<“Swap with reference :”<<endl;
swapreference(value1 , value2 );
cout<<“Value1 :”<<value1;
cout<<“value 2 : “<< value2 ;
cout<<“Swap with pointer :”<<endl;
swappointer(value1 , value2 );
cout<<“Value1 :”<<value1;
cout<<“value 2 : “<< value2 ;
cout<<“Swap with value :”<<endl;
swapvalue(value1 , value2 );
cout<<“Value1 :”<<value1;
cout<<“value 2 : “<< value2 ;
getch();
}
void swapvalue(int a ,int b )
{
int tenp ;
temp = a;
a=b;
b=temp ;
}
void swapreference(int & a , int & b )
{
int temp;
temp = a;
a=b;
b=temp ;
}
void swappointer(int *p , int *q)
{
int *  a;
*a=*p;
*p=*q;
*q=*a;
}

इस उदहारण मे swaping function को तीन अलग अलग तरीके से बनाया जाता है |
void swappointer(int *p , int *q); इस function मे pointer variable को use किया जाता है |
void swapvalue(int a ,int b ) ; इस function मे value को use किया जाता है |
void swapreference(int & a , int & b ) ; इस function मे reference variable को use किया जाता है | इसका आउटपुट होगा :
value1 : 100
value2:  200
Swap with reference :
value1 : 200
value2: 100
Swap with pointer :
value1 : 200
value2: 100
Swap with value :
value1 : 200
value2: 100

इस article मे reference variable को discuss किया है | आगे वाले reference variable को दुसरे data type के साथ discuss करेगे |

Sbistudy

Recent Posts

सती रासो किसकी रचना है , sati raso ke rachnakar kaun hai in hindi , सती रासो के लेखक कौन है

सती रासो के लेखक कौन है सती रासो किसकी रचना है , sati raso ke…

10 hours ago

मारवाड़ रा परगना री विगत किसकी रचना है , marwar ra pargana ri vigat ke lekhak kaun the

marwar ra pargana ri vigat ke lekhak kaun the मारवाड़ रा परगना री विगत किसकी…

10 hours ago

राजस्थान के इतिहास के पुरातात्विक स्रोतों की विवेचना कीजिए sources of rajasthan history in hindi

sources of rajasthan history in hindi राजस्थान के इतिहास के पुरातात्विक स्रोतों की विवेचना कीजिए…

2 days ago

गुर्जरात्रा प्रदेश राजस्थान कौनसा है , किसे कहते है ? gurjaratra pradesh in rajasthan in hindi

gurjaratra pradesh in rajasthan in hindi गुर्जरात्रा प्रदेश राजस्थान कौनसा है , किसे कहते है…

2 days ago

Weston Standard Cell in hindi वेस्टन मानक सेल क्या है इससे सेल विभव (वि.वा.बल) का मापन

वेस्टन मानक सेल क्या है इससे सेल विभव (वि.वा.बल) का मापन Weston Standard Cell in…

3 months ago

polity notes pdf in hindi for upsc prelims and mains exam , SSC , RAS political science hindi medium handwritten

get all types and chapters polity notes pdf in hindi for upsc , SSC ,…

3 months ago
All Rights ReservedView Non-AMP Version
X

Headline

You can control the ways in which we improve and personalize your experience. Please choose whether you wish to allow the following:

Privacy Settings
JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now