JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

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

Categories: c++ language in hindi

C++ : CALL BY REFERENCE ( EXAMPLE)

examples of C++ : CALL BY REFERENCE ( EXAMPLE) :- इससे पहले के article मे  function के type , strurcture और call by reference को discuss किया था | अब इस article मे function के उदाहरन को discuss करेग जिसमे call by reference को use किया जाता है |

उदाहरन -1

इस उदाहरन मे , square function को बनाया जाता है |

Explanation

सबसे पहले यूजर द्वारा data input किया जाता है | इसके बाद value को variable ‘a’ मे assign कर दिया जाता है |

इसके बाद square() मे variable ‘a’ के address को pass किया जाट है | इस function से प्राप्त आउटपुट को variable ‘o’ मे assign कर दिया जाता अहि \

उसके बाद variable ‘o’ की value display किया जाता है |

square () मे ,

square () मे variable ‘a’ के address को एक pointer variable ‘b’ मे assign किया जाता है |

इसके बाद int square = *b * *b से square किया जाता है | लेकिन  *b * *b को reader द्वारा समजना बहुत मुश्किल होता है |

इसलिए int square = (*b)* (*b) को use किया जाता है |

उसके बाद variable square की value को return किया जाता है |

source code

#include<iostream.h>

#include<conio.h>

#include<math.h>

void sqaure(int*);

void main()

{

int a ;

cout<<“Enter value : “;

cin>>a;

int output = sqaure(&a );

cout<<” Square output of a :”<<output<<endl;

}

getch();

}

void add(int *b)

{

int square = (*b)* (*b)  ;

return square;

}

इसका आउटपुट होता :-

Enter value  : 3

Square output of a : 9

उदाहरन -2

इस उदाहरन मे , cube function को बनाया जाता है |

Explanation

सबसे पहले यूजर द्वारा data input किया जाता है | इसके बाद value को variable ‘a’ मे assign कर दिया जाता है |

इसके बाद cube() मे variable ‘a’ के address को pass किया जाट है | इस function से प्राप्त आउटपुट को variable ‘o’ मे assign कर दिया जाता है |

उसके बाद variable ‘o’ की value display किया जाता है |

cube () मे ,

cube () मे variable ‘a’ के address को एक pointer variable ‘b’ मे assign किया जाता है |

इसके बाद int cube = *b * *b * *b से square किया जाता है | लेकिन  *b * *b को reader द्वारा समजना बहुत मुश्किल होता है |

इसलिए int cube = (*b)* (*b) * (*b) को use किया जाता है |

उसके बाद variable cube की value को return किया जाता है |

source code

#include<iostream.h>

#include<conio.h>

#include<math.h>

void cube (int*);

void main()

{

int a ;

cout<<“Enter value : “;

cin>>a;

int output = cube (&a );

cout<<” cube output of a :”<<output<<endl;

}

getch();

}

void cube(int *b)

{

int cube = (*b)* (*b)  ;

return cube;

}

उदाहरन -3

इस उदाहरन मे , power function को बनाया जाता है |

Explanation

सबसे पहले यूजर द्वारा  दो data input किया जाता है | इसके बाद value को variable ‘a’ और ‘b’ मे assign कर दिया जाता है | ‘a’ power function मे base होता है तब variable ‘b’ power function मे power होता है |

इसके बाद cube() मे variable ‘a’ और ‘b’ के address को pass किया जाट है | इस function से प्राप्त आउटपुट को variable ‘o’ मे assign कर दिया जाता है |

उसके बाद variable ‘o’ की value display किया जाता है |

power () मे ,

power () मे variable ‘a’ और ‘b’ के address को एक pointer variable ‘base’ और power मे assign किया जाता है |

इसके बाद loop चल्या जाता है  | loop तब तक चलता है जब तक control variable की value power से कम या सामान होती है |

इस loop की body मे ,  int o = o*base को calculate किया जाता है | ‘o’ की initail value ‘1’ होती है |

बाद मे variable ‘o’ की value को return कर दिया जाता है |

source code

#include<iostream.h>

#include<conio.h>

#include<math.h>

void power (int*, int*);

void main()

{

int a , b;

cout<<“Enter Base : “;

cin>>a;

cout<<“Enter Power : “;

cin>>b;

int output = power (&a ,&b );

cout<<” Power output :”<<output<<endl;

}

getch();

}

void cube(int *base , int *power)

{

int i = 0 ;

int o=1;

for(i=0;i<power ; i++)

{

o=o* base ;

}

return o;

}

इसका आउटपुट होगा :

Enter Base : 3

Enter Power :3

Power output :27

उदाहरन -2

इस उदाहरन मे , even – odd function को बनाया जाता है |

Explanation

सबसे पहले यूजर द्वारा data input किया जाता है | इसके बाद value को variable ‘a’ मे assign कर दिया जाता है |

इसके बाद even () मे variable ‘a’ के address को pass किया जाट है | इस function से प्राप्त आउटपुट को variable ‘o’ मे assign कर दिया जाता है |

उसके बाद variable ‘o’ की value display किया जाता है |

cube () मे ,

cube () मे variable ‘a’ के address को एक pointer variable ‘b’ मे assign किया जाता है |

इसके बाद  condition check किया जाता है | अगर  *b को 2 से divid किया जाता है अगर इसके remainder ‘0’ होती है तब  ‘1’ return  होगा |

अन्यथा  ‘0’ को return किया जाता है |

source code

#include<iostream.h>

#include<conio.h>

#include<math.h>

void even (int*);

void main()

{

int a ;

cout<<“Enter value : “;

cin>>a;

int count  = cube (&a );

if(count == 0)

{

cout<<” Number is even. “<<endl;

}

else

{

cout<<” Number is not even. “<<endl;

}

getch();

}

void even (int *b)

{

if((*b)% 2 == 0 )

{

return ‘0’;

}

else

{

return ‘1’ ;

}

}

इस article मे discuss किये गये उदाहरनो के level बहुत सरल है  आगे के article मे  और मुश्किल उदाहरनो को discuss करेगे |

Sbistudy

Recent Posts

सारंगपुर का युद्ध कब हुआ था ? सारंगपुर का युद्ध किसके मध्य हुआ

कुम्भा की राजनैतिक उपलकियाँ कुंमा की प्रारंभिक विजयें  - महाराणा कुम्भा ने अपने शासनकाल के…

4 weeks ago

रसिक प्रिया किसकी रचना है ? rasik priya ke lekhak kaun hai ?

अध्याय- मेवाड़ का उत्कर्ष 'रसिक प्रिया' - यह कृति कुम्भा द्वारा रचित है तथा जगदेय…

4 weeks ago

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

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

2 months ago

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

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

2 months ago

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

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

3 months ago

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

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

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