G.BALAJI MCA,M.Tech.,
Assistant Professor Of Computer Science,
Vivekanada College,Madurai.
 In C language we cannot make functions using same
name. But in C++ we can use function with same
name.
 For eg:
void add();
int add();
In C language, It’s not allowed in functions using
same name in same program
In C++ it’s allowed in same program but this is
wrong too...
They obey the function are some conditions
 Function overloading is defined as two or more functions
having same name but they should be differ in arguments.
 For eg:
Void add();
 Void add(int a);
 int add(double a);
 Void add (int a,int b);
These all are valid functions in the same program.
In this program four function have same name with different
arguments.
Void & int is return type in this program but return type is
doesn’t matter here. Arguments make the functions unique.
# include<iostream>
void add(int a,int b)
{
cout<<“ the addition of two numbers is “<<a+b<<endl;
}
void add(double a,double b)
{
cout<<“ the addition of two numbers is “<<a+b<<endl;
}
void main()
{
int first,second;
double fir,sec;
cout<< “enter two integers”<<endl;
cin>>first>>second; //we take input from user.
add(first,second);
cout<<“ enter two doubles value:”<<endl;
cin>>fir>>sec; //we take input from user.
add(fir,sec);}
In this program,
void add (int a, int b);
void add (double a, double b);
 Two different function with same name & different
arguments.
add (first, second);
add (fir,sec);
 We dont have to specify which function should be run.
 Complier automatically decides depending on types.

Function overloading in c++

  • 1.
    G.BALAJI MCA,M.Tech., Assistant ProfessorOf Computer Science, Vivekanada College,Madurai.
  • 2.
     In Clanguage we cannot make functions using same name. But in C++ we can use function with same name.  For eg: void add(); int add(); In C language, It’s not allowed in functions using same name in same program In C++ it’s allowed in same program but this is wrong too... They obey the function are some conditions
  • 3.
     Function overloadingis defined as two or more functions having same name but they should be differ in arguments.  For eg: Void add();  Void add(int a);  int add(double a);  Void add (int a,int b); These all are valid functions in the same program. In this program four function have same name with different arguments. Void & int is return type in this program but return type is doesn’t matter here. Arguments make the functions unique.
  • 4.
    # include<iostream> void add(inta,int b) { cout<<“ the addition of two numbers is “<<a+b<<endl; } void add(double a,double b) { cout<<“ the addition of two numbers is “<<a+b<<endl; } void main() { int first,second; double fir,sec; cout<< “enter two integers”<<endl; cin>>first>>second; //we take input from user. add(first,second); cout<<“ enter two doubles value:”<<endl; cin>>fir>>sec; //we take input from user. add(fir,sec);}
  • 5.
    In this program, voidadd (int a, int b); void add (double a, double b);  Two different function with same name & different arguments. add (first, second); add (fir,sec);  We dont have to specify which function should be run.  Complier automatically decides depending on types.