Function Overloading in C/Cpp

Function Overloading in C/Cpp

2 min read

Function overloading is a c++ programming feature that allows us to have more than one function having the same name but different parameter list, when I say parameter list, it means the data type and sequence of the parameters.

For example, the parameters list of a function myfun(int a, float b) is (int, float)which is different from the function myfun(float a, int b) parameter list (float, int).

Function overloading is a compile-time polymorphism.


void display(int a);
void display(float b);
void display(int a, float b);
void main()
{ int a= 5;
 float b=5.5;
void display(int a)
 cout<<"Integer number:"<<a;
void display(int b)
 cout<<"Float number:"<<b;
void display(int a, int b)
 cout<<"Integer number:"<<a<<"and float number:"<<b;


Integer number:5
Float number:5.5
Integer number:5 and float number:5.5

Advantage of function overloading

  • It speeds up the execution of programs.
  • The use of function overloading is to save memory space, consistency, and readability.
  • Function overloading exhibits the behavior of polymorphism which helps to get different behavior, although there will be some link using the same name of the function.
  • Function overloading is done for code re-usability, to save efforts, and also to save memory.
  • Code Maintenance is easy.

Disadvantage of function overloading

  • Function declarations that differ only in the return type cannot be overloaded.
  • Member function declarations with the same name and the same parameter types cannot be overloaded if any of them is static member function declaration.
Choose your Reaction!
Leave a Comment