SlideShare a Scribd company logo
Function Overloading
• Overloading🡪 refers to the use of same thing
for different purpose
• Function overloading-> We can use the same
function name to perform a verity of different
task
• Provided that the function should vary the
number or types of the arguments
Using the concept of function ovaerloading
• We can design functions with same function
name but with different argument list
• Difference in
• Type or
• number of arguments
Examples
function prototype /declaration
• int add(int a,int b);
• int add(int a,int b,int c);
• float add(float a,int b);
Function call
• add(5,10);
• add(5,6,3);
• add(4.6,7.9);
Function definition
int add (int a, int d)
{
int c ;
c=a+d;
return c
}
int add (int a, int d,int e)
{
int c ;
c=a+d+e;
return c
}
******************
float add (float a, int d)
{
float c ;
c=a+d;
return c
}
• The function would perform different
operations depending on the argument list in
the function call
#include<iostream.h>
float volume(float l);
float volume(float r,float h);
float volume(float l,float b,float h);
void main()
{
float l,r,b,h,t;
clrscr();
cout<<“nEnter the Length of Cube: n”;
cin>>l;
t=volume(l);
cout<<“nnVolume of Cube: “<<t;
cout<<“nnEnter the Radius & Hieght of
Cylinder: n”;
cin>>r>>h;
t=volume(r,h);
cout<<“nnVolume of Cylinder: “<<t;
cout<<“nnEnter the Length,Breadth & Hieght of
Rectangle: n”;
cin>>l>>b>>h;
t=volume(l,b,h);
cout<<“nnVolume of Rectangle: “<<t;
getch();
}
float volume(float l) //Cube
{
float f;
f=l*l*l;
return f;
}
float volume(float r,float h)
//Cylinder
{
float vl=3.14*r*h;
return vl;
}
float volume(float l,float b,float h)
{ float f=l*b*h;
return f;
}
• Function Overloading is an example of
compile time polymorphism

More Related Content

PPTX
Function_Overloading_in_CPP its uses and examples.
PPTX
Function overloading
PPT
Polymorphism
PPT
FunctionOverloadingwithpolymorphismconcept.ppt
PPT
class12 3 Function Overloadingin ooooop .ppt
PPT
3 Function Overloading
PPTX
Functions in C++ (OOP)
PDF
03 function overloading
Function_Overloading_in_CPP its uses and examples.
Function overloading
Polymorphism
FunctionOverloadingwithpolymorphismconcept.ppt
class12 3 Function Overloadingin ooooop .ppt
3 Function Overloading
Functions in C++ (OOP)
03 function overloading

Similar to Function Overloading in C++ programming language (20)

PPTX
Function overloading and overriding
PPT
Function Overloading.ppt
PPTX
Presentation on polymorphism in c++.pptx
PPTX
Function overloading
PPTX
Silde of the cse fundamentals a deep analysis
PPTX
Operator Overloading & Function Overloading
PPTX
Functions in C++ programming language.pptx
PPTX
functions over-loading, over-hiding and over-riding
PPT
Function overloading in c++
PPTX
Lecture 4, c++(complete reference,herbet sheidt)chapter-14
PDF
2nd puc computer science chapter 8 function overloading
PPT
OODP UNIT 2 Function overloading
PPTX
function overloading
PPTX
oops.pptx
PPTX
Function overloading
PDF
Overloading
PPT
3d7b7 session4 c++
PPT
14 operator overloading
PDF
overloading in C++
Function overloading and overriding
Function Overloading.ppt
Presentation on polymorphism in c++.pptx
Function overloading
Silde of the cse fundamentals a deep analysis
Operator Overloading & Function Overloading
Functions in C++ programming language.pptx
functions over-loading, over-hiding and over-riding
Function overloading in c++
Lecture 4, c++(complete reference,herbet sheidt)chapter-14
2nd puc computer science chapter 8 function overloading
OODP UNIT 2 Function overloading
function overloading
oops.pptx
Function overloading
Overloading
3d7b7 session4 c++
14 operator overloading
overloading in C++
Ad

Recently uploaded (20)

PPTX
Big Data Technologies - Introduction.pptx
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Machine learning based COVID-19 study performance prediction
PDF
Encapsulation theory and applications.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Cloud computing and distributed systems.
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Big Data Technologies - Introduction.pptx
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Machine learning based COVID-19 study performance prediction
Encapsulation theory and applications.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Diabetes mellitus diagnosis method based random forest with bat algorithm
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Network Security Unit 5.pdf for BCA BBA.
Cloud computing and distributed systems.
Review of recent advances in non-invasive hemoglobin estimation
Reach Out and Touch Someone: Haptics and Empathic Computing
Building Integrated photovoltaic BIPV_UPV.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Dropbox Q2 2025 Financial Results & Investor Presentation
Encapsulation_ Review paper, used for researhc scholars
Advanced methodologies resolving dimensionality complications for autism neur...
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Programs and apps: productivity, graphics, security and other tools
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Ad

Function Overloading in C++ programming language

  • 1. Function Overloading • Overloading🡪 refers to the use of same thing for different purpose • Function overloading-> We can use the same function name to perform a verity of different task • Provided that the function should vary the number or types of the arguments
  • 2. Using the concept of function ovaerloading • We can design functions with same function name but with different argument list • Difference in • Type or • number of arguments
  • 3. Examples function prototype /declaration • int add(int a,int b); • int add(int a,int b,int c); • float add(float a,int b);
  • 4. Function call • add(5,10); • add(5,6,3); • add(4.6,7.9);
  • 5. Function definition int add (int a, int d) { int c ; c=a+d; return c } int add (int a, int d,int e) { int c ; c=a+d+e; return c } ****************** float add (float a, int d) { float c ; c=a+d; return c }
  • 6. • The function would perform different operations depending on the argument list in the function call
  • 7. #include<iostream.h> float volume(float l); float volume(float r,float h); float volume(float l,float b,float h); void main() { float l,r,b,h,t; clrscr(); cout<<“nEnter the Length of Cube: n”; cin>>l; t=volume(l); cout<<“nnVolume of Cube: “<<t; cout<<“nnEnter the Radius & Hieght of Cylinder: n”; cin>>r>>h; t=volume(r,h); cout<<“nnVolume of Cylinder: “<<t; cout<<“nnEnter the Length,Breadth & Hieght of Rectangle: n”; cin>>l>>b>>h; t=volume(l,b,h); cout<<“nnVolume of Rectangle: “<<t; getch(); } float volume(float l) //Cube { float f; f=l*l*l; return f; } float volume(float r,float h) //Cylinder { float vl=3.14*r*h; return vl; } float volume(float l,float b,float h) { float f=l*b*h; return f; }
  • 8. • Function Overloading is an example of compile time polymorphism