हिंदी माध्यम नोट्स
reference in c++ language , what is References vs Pointers , References as Parameters ,as Return Value
reference variable का use किसी variable को name से जोड़ने के लिए किया जाता अहि | variable को पहले declare किया जता है | जब किसी variable के लिए reference को initail किया जाता है तब reference name या variable दोनों को variable के लिए use किया जा सकता है |
References vs Pointers
reference को pointer मे थोडा समानता होती है | लेकिन इन दोनों concept मे काफी difference होता है | इस्मा difference निन्म होता है :-
कभी कभी किसिसी reference variable को null declare नहीं किया जा सकता है | reference variable को किसिस variable के लिए एक storage को occupy कर्ण एके लिए use किया जाता है |
जब किसि reference variable के लिए object को declare किया जाता है तब इसे किसि दुसरे object के लिए use नहीं किया जा सकता है | लेकिन pointer variable को किसि दुसरे variable को कभी भी utilize किया जा सकता है |
reference variable को जब create किया जाता है initial किया जाता है जबकि pointer variable को कभी भी initail किया जाता है |
Creating References in C++
जब किसी variable को memory को access करने के लिए variable name को use किया जाता है | और reference को किसी variable के memory को access करने के लिए use किया जासकता है | और जब किसी variable को memory को allocate करने के लिए variable name को use किया जाता है | और reference को भी किसी variable के memory को allocate करने के लिए use किया जासकता है | इसका उदाहरन निन्म है :
int a = 17;
variable a के लिए reference को declare करने के लिए निन्म syntax है :-
int& r = i;
किसी reference को declare करने लिए ‘&’ को use किया जाता है | इस syntax से reference ‘r’ को declare किया जाता है जिसे ‘a’ की value से initial किया जाता है |
उदाहरन 1 :
इस उदाहरन मे reference ‘r’ को declare किया जाता है जिसे ‘a’ की value से initial किया जाता है | और इसके अलवा refDouble, double type reference है जिसे double variable f के लिए use किया जाता है |
Source code
#include <iostream>
using namespace std;
int main () {
// declare simple variables
int a;
double f;
// declare reference variables
int& ref = a;
double& refDouble = f;
a = 12;
cout << “Value of a : ” << a << endl;
cout << “Value of reference a : ” << a << endl;
f = 134.7;
cout << “Value of f : ” << f << endl;
cout << “Value of reference f ” << refDouble << endl;
return 0;
}
जब उपर वाले उदाहरनो को execute किया जाता है जब इसका
Value of a : 12
Value of reference a : 12
Value of f : 134.7
Value of reference f : 134.7References को किसी function argument lists और function return values की तरह use किया जा सकता है | आगे इन concept को discuss किया जाता है |
1 References as Parameters
जब किसी reference को function parameter मे pass किया जाता है तब इस method को call by reference कहते है | इस method मे pass की गयी reference को नार्मल variable से ज्यादा अच्छा रहता है |
उदाहरन 2 :
इस उदाहरन मे reference ‘r’ को declare किया जाता है जिसे ‘a’ की value से initial किया जाता है | और इसके अलवा ‘f’, double type reference है जिसे double variable b के लिए use किया जाता है |इसके बाद दोनों reference को function multiplication() मे pass किया जाता है |
Source code
#include <iostream>
using namespace std;
void main () {
// declare simple variables
int a;
int b ;
cout << “Value of a : ” << endl;
cin>>a;
cout << “Value of b : ” << endl;
cin>>b;
int c = multiplication(a,b);
cout << “Output of multiplication : ” <<c<< endl;
getch();
}
void multiplication(int &r , int &f )
{
int mul ;
mul = r*f;
return mul ;
}
2 Reference as Return Value
जब किसी reference को किसी function मे से return किया जाता है तब reference को return जा सकता है |
Source code
#include <iostream>
using namespace std;
void main () {
// declare simple variables
int a;
int b ;
cout << “Value of a : ” << endl;
cin>>a;
cout << “Value of b : ” << endl;
cin>>b;
int c = multiplication(a,b);
cout << “Output of multiplication : ” <<c<< endl;
getch();
}
void multiplication( r , f )
{
int mul ;
mul = r*f;
return (&mul) ;
}
इस article मे reference को discuss किया जाता है |
Recent Posts
मालकाना का युद्ध malkhana ka yudh kab hua tha in hindi
malkhana ka yudh kab hua tha in hindi मालकाना का युद्ध ? मालकाना के युद्ध…
कान्हड़देव तथा अलाउद्दीन खिलजी के संबंधों पर प्रकाश डालिए
राणा रतन सिंह चित्तौड़ ( 1302 ई. - 1303 ) राजस्थान के इतिहास में गुहिलवंशी…
हम्मीर देव चौहान का इतिहास क्या है ? hammir dev chauhan history in hindi explained
hammir dev chauhan history in hindi explained हम्मीर देव चौहान का इतिहास क्या है ?…
तराइन का प्रथम युद्ध कब और किसके बीच हुआ द्वितीय युद्ध Tarain battle in hindi first and second
Tarain battle in hindi first and second तराइन का प्रथम युद्ध कब और किसके बीच…
चौहानों की उत्पत्ति कैसे हुई थी ? chahamana dynasty ki utpatti kahan se hui in hindi
chahamana dynasty ki utpatti kahan se hui in hindi चौहानों की उत्पत्ति कैसे हुई थी…
भारत पर पहला तुर्क आक्रमण किसने किया कब हुआ first turk invaders who attacked india in hindi
first turk invaders who attacked india in hindi भारत पर पहला तुर्क आक्रमण किसने किया…