JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

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

Categories: c++ language in hindi

class with reference variable in c++ language , what is C++ : Reference variable with Class in hindi

what is C++ : Reference variable with Class in hindi , class with reference variable in c++ language :-
इससे पहले के article मे reference variable और pass by reference method को discuss किया है अब इस article मे reference variable को class के साथ use करने के method को discuss करेगे |

class with reference variable

c++ मे class को reference variable की तरह function मे pass करने के method एक अलग ही महत्व है | इसे किसी प्रोग्राम को समजना बहुत जरुरी है |इस article मे , हम string , ostream , istream , ifstream class मे reference variable को pass करने के method को discuss करेगे | इसके लिए निन्म उदाहरानो अच्छी तरह observe काना बहुत जरुरी है |
#include<iostream.h>
#include<conio.h>
#include<string.h>
using namespace std;
string(const string &first , const string &second);
const string &name1(string &first , const string &second);
const string &name1(string &first , const string &second);
void main()
{
string input;
string copy;
string output;
cout<<“Enter Your name :”<<endl;
getline(cin,input);
copy=input ;
cout<<“Your Name is “<<input<<endl;
output= name1(input,’*****’);
cout<<“User name is “<<output<<endl;
cout<<“Your name is “<<input<<endl;
output=name2(input,’######’);
cout<<“User name is “<<output<<endl;
cout<<“Your name is “<<input<<endl;
cout<<“user name reset “<<endl;
input = copy;
output=name2(input,’@@@@@’);
cout<<“User name is “<<output<<endl;
cout<<“Your name is “<<input<<endl;
getch();
}
string(const string &first , const string &second)
{
string temp ;
temp = first + second ;
return temp ;
}
const string &name1(string &first , const string &second)
{
first = second + first + second ;
return first ;
}
const string &name1(string &first , const string &second)
{
string temp ;
temp= second + fisrt + second ;
return temp ;
}
इस उदहारण मे दो string argument first और second को use किया गया है और इसके अलावा string function को use किया गया है  | इस string function से एक नए string को बनाया जाता है | इस function मे pass किये गये arguments const है इसलिए function द्वारा generate की गये आउटपुट सामान होगा अगर इसमें पास किये गये string object समाए होगा तब |
function const string &name1(string &first , const string &second) मे first और second दो नए string है | और इसके reference को use किया गया है क्त्योकी इस function मे कोई भी नए string को declare नहीं किया गया है | बल्कि नए object को पुराने object मे assign किया गया है | यहा पर const keyword ये define करता है इस function को use किया जा सकता अहि लेकिन इसकी value को change नहीं किया जा सकता है |
function string(const string &first , const string &second) मे , temp को use किया गया है जो की एक नया object है | और इस function reference function नहीं है इसलिए temp को return किया गया है | और string input मे कोई effect नहीं पड़ता है |
लेकिन function const string &name1(string &first , const string &second) मे reference function को use किया गया है | इसलिए variable first की value मे changes होते है |
Reference variable को use करने के लिए Rules
reference variable को दो task के लिए use किया जा सकता है |
1. calling function मे data object की value को change करने के लिए किया जाता है |
2. प्रोग्राम की speed को बढ़ाने के लिए use किया जाता है |
जब किसी function मे बड़े data type जैसे string और  struture को pass किया जाता है तब reference variable को use किया जाता है | ये दोनों pointer variable को use करने के लिए प्रेरित करता है |
function से बिना किसी changes data निन्म condition मे पास किया जाता है |
1.अगर data object की size बहुत छोटी होती है जैसे छोटा structure या built in data | तब call by value को use किया जाता है |
2.अगर data object array होती है तब call by  pointer को use किया जाता है | pointer को const declare करना चाहिए |
3.अगर data object , बहुत बड़ा struture हो तब const pointer और const reference को use किया जा सकता है | लेकिन const reference से प्रोग्राम की
एफिशिएंसी को बढाया जाता है | जब किसी प्रोग्राम मे space और time को बचना होता है तब pointer और reference को const declare करना चाहिए |
4.जब data object class object हो तब call by reference को use किया जाता है | class को design करने के लिए reference को use किया जाता है |
जब किसी function मे changes के साथ data type को declare किया जाता है तब
1.जब data object built in data हो तब call by pointer को use किया जाता है | data object को fixit() मे pass किया जाताजाता है |
2.जब data object array होता है तब pointer variable को use किया जाता है |
3.जब data type structure होता है तब reference को use किया जाता  है |
4.जब object class होता है तब reference को use किया जाता है |
उदाहरन के लिए
#include<iostream.h>
#include<conio.h>
void display (int * )
void main()
{
int size[10];
cout<<“Enter Size : “;
for(i=0;i<10;i++)
{
cin>>size[i];
}
display(size);
getch();
}
void display ( int * s )
{
cout<<“Size for 10 Student :”;
for(i=0;i<10;i++)
{
cout<<*s;
s++;
}
}
इस उदहारण मे , array को use किया जाता है इसके function मे  pointer variable ‘s’ को declare किया जाता है | और call by pointer को use किया जाता है |
इसका आउटपुट होगा :
Enter Size : 12 23 12 33 43 23 12 23 23 34
Size for 10 Student :
12 23 12 33 43 23 12 23 23 34
इस article मे , reference variable को class के साथ उपयोग करने के method को discuss किया गया है | आगे के article मे c++ templates को 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