JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

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

Categories: c++ language in hindi

reference in c++ language , what is References vs Pointers , References as Parameters ,as Return Value

References as Parameters ,as Return Value , reference in c++ language , what is References vs Pointers :-
इससे पहले के article मे namespace और template को discuss किया था अब इस article मे  reference variable को discuss करेगे जो की c++ language का बहुत महत्व  पूर्ण concept है |
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 किया जाता है |

Sbistudy

Recent Posts

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

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

18 hours ago

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

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

18 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