AdBlocker Detected!

Hello! To continue reading aasansolution.in, please disable your AdBlocker or Brave Shield.

Allowing ads helps us keep our customized Tally TDLs and tools completely free for everyone.

I have whitelisted it - Refresh Page
AS

Question 7. What do you mean by function overloading? Explain with Examples. फंक्शन ओवरलोडिंग से आप क्या समझते हैं? उदाहरण सहित समझाइए।


 

Multiple functions with same name is known as function overloading or function polymorphism.

Polymorphism means one function having many forms. The overloaded function must

Be different in its argument list and with different data types. The examples of overloaded functions are given below. All the functions defined should be equivalent to their prototypes.


एक ही नाम वाले कई फंक्शन को फंक्शन ओवरलोडिंग या फंक्शन पॉलीमॉर्फिज्म के रूप में जाना जाता है। बहुरूपता का अर्थ है एक फंक्‍शन जिसको कई रूपों में प्रयोग करना हो। फंक्‍शन ओवरलोडिंग में फंक्‍शन में पास किये जाने वाले Argument व डाटा टाइप अलग प्रकार के होने चाहिए। Function Overloading का उदाहरण नीचे दिए गया हैं।ओवरलोडेड सभी फंक्‍शनों में उनके प्रोटोटाइप एक जैसे होने चाहिए।

int sqr (int);

float sqr (float);

long sqr (long);

 

Example:

Program to calculate square of an integer and float number.

Define function sqr () and use function-overloading concept.

 

# include <iostream.h>

# include <conio.h>

int sqr(int);

float sqr(float);

main ()

{

int a=15;

float D=2.5;

cout <<“Square = “<<sqr(a) <<“\n”;

cout <<“Square “<< sqr(b) <<“\n”;

return 0;

}

 

int sqr(int s)

{

return (s*s);

}

 

float sqr (float j)

{

return (j *j);

}

 

OUTPUT

Square =225

Square=6.25

Fast Index