#include<iostream.h>
void display(char,int);
void display(int,int);
void main()
{
display('a',10);
display(10,5);
}
void display(char c,int n)
{
for(;n>0;n--)
cout<<c<<" ";
cout<<endl;
}
void display(int a,int b)
{
for(;b>0;b--)
cout<<a<<" ";
cout<<endl;
}
Output:
a a a a a a a a a a
10 10 10 10 10
The following example illustrate a function overloading using different number of parameter and same data type.
Funtion Overloading:
An overloading function appears to perform different activities depending on the kind of data send to it. Function overloading is the logical method of calling several functions with the same name. Each redefinition of a function must use different type of parameters, or different sequence of parameters, or different sequence of parameters, or different number of parameters. The advantages of function overloading are:
The following example illustrate a function overloading using different type of parameter.
void display(char,int);
void display(int,int);
void main()
{
display('a',10);
display(10,5);
}
void display(char c,int n)
{
for(;n>0;n--)
cout<<c<<" ";
cout<<endl;
}
void display(int a,int b)
{
for(;b>0;b--)
cout<<a<<" ";
cout<<endl;
}
Output:
a a a a a a a a a a
10 10 10 10 10
The following example illustrate a function overloading using different number of parameter and same data type.
Funtion Overloading:
An overloading function appears to perform different activities depending on the kind of data send to it. Function overloading is the logical method of calling several functions with the same name. Each redefinition of a function must use different type of parameters, or different sequence of parameters, or different sequence of parameters, or different number of parameters. The advantages of function overloading are:
- Eliminating the use of different function name for the same operation.
- Helps to understand, debug and grasp easily.
- Easy maintainability of the code.
The following example illustrate a function overloading using different type of parameter.
No comments:
Post a Comment