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

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

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

16 hours ago

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

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

16 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