JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

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

Categories: c++ language in hindi

C++ : Default Parameter or Function Overloading in hindi , what is Default Parameter or Function Overloading c++ language

what is Default Parameter or Function Overloading c++ language , C++ : Default Parameter or Function Overloading in hindi :-
इससे पहले के article मे , function के basic structure , function के type और function के उदाहरानो को discuss किया | अब इस article मे function  overloading को discuss करेगे |Function Overloading
जब किसी दो या दो अधिक functions जिनका नाम same होता है लेकिन arguments अलग अलग होता है तब function overloading कहते है | इस article मे function overloading को discuss करेगे |
function किसी programming का एक छोटा सा segment होता है जो एक sepecfic कार्य के लिए बनाया जाता है | c++ language मे , दो सामान नाम वाले function को अलग अलग consider किया जाता है अगर इसमें pass argument की सख्या और type अलग अलग होती है |
दो function जिनका नाम सामान होता  है लेकिन argument की सख्या और type अलग अलग होता है उन functions को overload function कहते है | उदाहरन के लिए :
int add(){}
int add(int a ){}
int add(int a ,int b ){}
int add(int a , float b){}
इस उदहारण मे चार function होता है | उपर दिए गये function का नाम add( ) है लेकिन ये सभी function को अलग अलग consider किया जाता है | overload function मे argument अलग अलग होना चाहिए लेकिन return statement का अलग होना complusy नहीं होना चाहिए | अतः निन्म function function overload function नहीं है :
int add(int){}
float add(int , int ) {}
इन उदहारण मे  int add(int){} और float add(int , int ) {} overload function नहीं है |क्योकि दोनों functions का return type अलग अलग होता है |
#include <iostream>
#include<conio.h>
using namespace std;
// Function prototype (declaration)
void print (int);
void print (float);
void print(double);
void  main()
{
int number ;
float number1;
float number2;
cout<<“Enter integer number : “;
cin >> number;
cout<<“Enter float number : “;
cin >> number1;
cout<<“Enter double number : “;
cin >> number2;
// Function call
print(number);
print(number1);
print(number2);
getch();
}
void print (int a)
{
cout<<“You enter integer”<<a;
}
void print ( float a)
{
cout<<“You enter float value “<<a;
}
void print (double a)
{
cout<<“You enter double value “<<a;
}
इस उदहारण मे  void print (int); , void print (float); और  void print(double); overload functions है इन सभीfunction का type void है लेकिन इसमें pass किये जाने वाली value का type अलग अलग होता है | in function मे return type सामान है |

function overloading का उदहारण :
#include <iostream>
#include<conio.h>
using namespace std;
// Function prototype (declaration)
float  RoundOff( int );
int  RoundOff(float);
void  main()
{
int number ;
float number1;
float number2;
cout<<“Enter integer number : “;
cin >> number;
cout<<“Enter float number : “;
cin >> number1;
cout<<“round off value of number :”<<RoundOff( number ) <<endl;
cout<<“round off value of number1 :”<<RoundOff( number1 ) <<endl;
getch();
}
int RoundOff(int a)
{
if(a<0)
a=-a;
return a;
}
float  RoundOff(int a)
{
if(a<0.0)
a=-a;
return a;
}
इस उदाहरन मे , float  RoundOff( int ); और  int  RoundOff(float); overload function है | इन function का return type और argument type दोनों  ही अलग अलग होता है |
पहले function मे integer type variable को pass किया जाता है | और दुसरे function मे float type value pass किया जाता है |

Default value
c++ language मे function parameter की default value को initial किया जा सकता है | एसे argument को default parameter कहते है |जब किसी argument को function मे call नहीं किया जाता है तब इन parameter को default parameter कहते है | default parameter को function prototype मे pass किया जाता है | इसका उदहारण निन्म है :-
#include <iostream>
#include<conio.h>
using namespace std;
// Function prototype (declaration)
void printline (int i =1 , char = ‘*’)
void  main()
{
int number ;
float number1;
cout<<“Enter integer number : “;
cin >> number;
cout<<“Enter float number : “;
cin >> number1;
printline ();
cout<<” You enter :”<<number<<endl;
printline(“#”);
cout<<“You enter :”<<number1<<endl;
printline(5,’$’);
getch();
}
void printline(int n , char c)
{
for(int i=0;i<n;i++)
{
cout<<c;
}
}
इसका आउटपुट होगा :
Enter integer number : 12
Enter float number : 12.22
*
You enter : 12
#
You enter : 12.22
$$$$$

इस उदहारण मे जब
printline() को call किया जाता है | तो इसमें कोई भी argument pass नहीं किया जाता है इसलिए इसमें default char = ‘*’ ओत int i= 1 को use किया जाता है |
और
printline(“#”) को call किया जाता है तो इसमें केवल एक argument को पास किया गया है इसलिए इसमें दुसरे argument की default value को consider किया जाता है |
और
printline(5,’$’); को call किया जाता है इसमें दोनों argument को पास किया जाता है |

default value को use करने के लिए निन्म rules को फॉलो किया जाता है :-
1.किसी default parameter को normal parameter से मिक्स नहीं किया जाता है |उदहारण के लिए
int add(int a , int b =3, int c );
ये उदाहरण error message देता है क्योकि default parameter ‘b’ को नार्मल parameter के बीच declare किया गया है |
2.अगर एक बार default parameter को देकाल्रे कर दिया जाता है तब उसके बाद सभी value को default parameter बनाना पड़ता है | उदाहरन के लिए
int add(int a=9 , int b =3, int c );
ये उदाहरन भी error message देता है क्योकि default parameter ‘b’ के बाद सभी parameter भी default होता है |

Sbistudy

Recent Posts

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

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

3 weeks ago

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

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

3 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