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

मालकाना का युद्ध malkhana ka yudh kab hua tha in hindi

malkhana ka yudh kab hua tha in hindi मालकाना का युद्ध ? मालकाना के युद्ध…

4 weeks ago

कान्हड़देव तथा अलाउद्दीन खिलजी के संबंधों पर प्रकाश डालिए

राणा रतन सिंह चित्तौड़ ( 1302 ई. - 1303 ) राजस्थान के इतिहास में गुहिलवंशी…

4 weeks ago

हम्मीर देव चौहान का इतिहास क्या है ? hammir dev chauhan history in hindi explained

hammir dev chauhan history in hindi explained हम्मीर देव चौहान का इतिहास क्या है ?…

4 weeks ago

तराइन का प्रथम युद्ध कब और किसके बीच हुआ द्वितीय युद्ध Tarain battle in hindi first and second

Tarain battle in hindi first and second तराइन का प्रथम युद्ध कब और किसके बीच…

4 weeks ago

चौहानों की उत्पत्ति कैसे हुई थी ? chahamana dynasty ki utpatti kahan se hui in hindi

chahamana dynasty ki utpatti kahan se hui in hindi चौहानों की उत्पत्ति कैसे हुई थी…

1 month ago

भारत पर पहला तुर्क आक्रमण किसने किया कब हुआ first turk invaders who attacked india in hindi

first turk invaders who attacked india in hindi भारत पर पहला तुर्क आक्रमण किसने किया…

1 month 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