Function Overloading with an Example in C++

Video Tutorials
Artificial Intelligence Tutorial
Machine Learning Projects TutorialPython Video tutorial
Computer Graphics Video TutorialC++ Video Tutorial
Big Data Analytics Video TutorialSoft Computing Video Tutorial
Placement Video TutorialJava Video Tutorial

Function Overloading with an Example in C++

In this tutorial, we will Learn:

What is function overloading in C++?

How to write a C++ program to find the areas of the circle (PI * r * r), rectangle (l * b), and square (x * x) by getting the r, l, b, and x through keyboard and printing the areas on the console using the method area() by applying the concept of function overloading.


Video Tutorial:

Function overloading means, two or more functions have the same names but different argument lists.

The arguments may differ in the type of arguments or number of arguments, or both.

However, the return types of overloaded methods can be the same or different is called function overloading.

Function overloading conceptshelps us to use the same function names multiple time in the same program.

Following program demonstrates the overloaded function to find the area of the circle, rectangle, and square.

 using namespace std;

 int area(int x)
     return x*x; 

int area(int l, int b) 
     return l*b;

 double area(double r)
     return 3.142*r*r;

 int main()
     int x, l, b;
     double r;
     cout<<"Enter the length of a square: ";
     cout<<"Enter the length of rectangle: ";
     cout<<"Enter the width of rectangle: ";
     cout<<"Enter the radius of circle: ";
     cout<<endl<<"The area of square is "<<area(x)<<endl;
     cout<<endl<<"The area of rectangle is "<<area(l, b)<<endl;
     cout<<endl<<"The area of circle is "<<area(r)<<endl;


Enter the length of a square: 10

Enter the length of rectangle: 10

Enter the width of rectangle: 15

Enter the radius of circle: 5.5

The area of square is 100

The area of rectangle is 150

The area of circle is 95.0455


In this article, we understood What is Function Overloading with an Example in C++ and wrote an overloaded function to find the area of the circle, rectangle, and square.

If you like the tutorial share it with your friends. Like the Facebook page for regular updates and YouTube channel for video tutorials.

Leave a Comment

Your email address will not be published. Required fields are marked *