SlideShare a Scribd company logo
1 of 5
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.

More Related Content

What's hot

Lec 26.27-operator overloading
Lec 26.27-operator overloadingLec 26.27-operator overloading
Lec 26.27-operator overloading
Princess Sam
 
08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt
Tareq Hasan
 
Operator overloadng
Operator overloadngOperator overloadng
Operator overloadng
preethalal
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
Kamal Acharya
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
Kumar
 
#OOP_D_ITS - 5th - C++ Oop Operator Overloading
#OOP_D_ITS - 5th - C++ Oop Operator Overloading#OOP_D_ITS - 5th - C++ Oop Operator Overloading
#OOP_D_ITS - 5th - C++ Oop Operator Overloading
Hadziq Fabroyir
 

What's hot (20)

Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
OPERATOR OVERLOADING IN C++
OPERATOR OVERLOADING IN C++OPERATOR OVERLOADING IN C++
OPERATOR OVERLOADING IN C++
 
Operator overloading and type conversions
Operator overloading and type conversionsOperator overloading and type conversions
Operator overloading and type conversions
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
 
Lec 26.27-operator overloading
Lec 26.27-operator overloadingLec 26.27-operator overloading
Lec 26.27-operator overloading
 
operator overloading
operator overloadingoperator overloading
operator overloading
 
08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt
 
Operator overloading and type conversion in cpp
Operator overloading and type conversion in cppOperator overloading and type conversion in cpp
Operator overloading and type conversion in cpp
 
Functions in c++,
Functions in c++,Functions in c++,
Functions in c++,
 
operator overloading & type conversion in cpp over view || c++
operator overloading & type conversion in cpp over view || c++operator overloading & type conversion in cpp over view || c++
operator overloading & type conversion in cpp over view || c++
 
14 operator overloading
14 operator overloading14 operator overloading
14 operator overloading
 
06. operator overloading
06. operator overloading06. operator overloading
06. operator overloading
 
Lecture5
Lecture5Lecture5
Lecture5
 
Operator overloadng
Operator overloadngOperator overloadng
Operator overloadng
 
Operator overloading in C++
Operator overloading in C++Operator overloading in C++
Operator overloading in C++
 
Unary operator overloading
Unary operator overloadingUnary operator overloading
Unary operator overloading
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
#OOP_D_ITS - 5th - C++ Oop Operator Overloading
#OOP_D_ITS - 5th - C++ Oop Operator Overloading#OOP_D_ITS - 5th - C++ Oop Operator Overloading
#OOP_D_ITS - 5th - C++ Oop Operator Overloading
 
Operator overloading
Operator overloading Operator overloading
Operator overloading
 

Similar to Function overloading in c++

Principles of object oriented programing
Principles of object oriented programingPrinciples of object oriented programing
Principles of object oriented programing
Ahammed Alamin
 

Similar to Function overloading in c++ (20)

Function overloading and overriding
Function overloading and overridingFunction overloading and overriding
Function overloading and overriding
 
C++
C++C++
C++
 
Java modular extension for operator overloading
Java modular extension for operator overloadingJava modular extension for operator overloading
Java modular extension for operator overloading
 
Function overloading
Function overloadingFunction overloading
Function overloading
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
Function
FunctionFunction
Function
 
Overview of c#
Overview of c#Overview of c#
Overview of c#
 
C vs c++
C vs c++C vs c++
C vs c++
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
C language function
C language functionC language function
C language function
 
C and C ++ Training in Ambala ! BATRA COMPUTER CENTRE
C and C ++ Training in Ambala ! BATRA COMPUTER CENTREC and C ++ Training in Ambala ! BATRA COMPUTER CENTRE
C and C ++ Training in Ambala ! BATRA COMPUTER CENTRE
 
Generics On The JVM (What you don't know will hurt you)
Generics On The JVM (What you don't know will hurt you)Generics On The JVM (What you don't know will hurt you)
Generics On The JVM (What you don't know will hurt you)
 
C++ Tutorial
C++ TutorialC++ Tutorial
C++ Tutorial
 
2nd puc computer science chapter 8 function overloading
 2nd puc computer science chapter 8   function overloading 2nd puc computer science chapter 8   function overloading
2nd puc computer science chapter 8 function overloading
 
Polymorphism in java
Polymorphism in java Polymorphism in java
Polymorphism in java
 
Chapter 1.ppt
Chapter 1.pptChapter 1.ppt
Chapter 1.ppt
 
Computer science principals in terms of Programming
Computer science principals in terms of ProgrammingComputer science principals in terms of Programming
Computer science principals in terms of Programming
 
Principles of object oriented programing
Principles of object oriented programingPrinciples of object oriented programing
Principles of object oriented programing
 
Polymorphism in java
Polymorphism in javaPolymorphism in java
Polymorphism in java
 
C function presentation
C function presentationC function presentation
C function presentation
 

Recently uploaded

Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 

Recently uploaded (20)

Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 

Function overloading in c++

  • 1. G.BALAJI MCA,M.Tech., Assistant Professor Of Computer Science, Vivekanada College,Madurai.
  • 2.  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
  • 3.  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.
  • 4. # 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);}
  • 5. 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.