SlideShare una empresa de Scribd logo
1 de 8
Functions in C+
       +
    Presented by Sachin
         Sharma
Function Overloading
• C++ enables several functions of the
  same name to be defined, as long as
  these functions have different sets of
  parameters (at least as far as their
  types are concerned). This capability
  is called function overloading.
Example To Use The concept of function
                  overloading
# include<iostream.h>
# include<conio.h>
void area (float r);
void area (float l, float b);
void main()
{
         float r1, l1, b1;
clrscr();
         cout<<“ Enter value of r1: ”<<endl;
         cin>>r1;
         cout<<“ Enter value of l1: ”<<endl;
         cin>>l1;
         cout<<“ Enter value of b1: ”<<endl;
         cin>>b1;
cout<<“ Area of the circle is “<<endl;
area (r1);
cout<<“ Area of the rectangle is “<<endl;
area (l1, b1);
}
void area (float r)
{
         float a = 3.14*r*r;
         cout<<“ Area = “<<a<<endl;
}
void area ()
{
         float a1 = l*b;
Output
Enter value of r1:
2
Enter value of l1:
4
Enter value of b1:
6
Area of the circle is
Area = 12.56
Area of the rectangle is
Area = 24
Inline Functions in C++
• Whenever we call a function, control jump to
  function and come back to caller program when
  execution of function is completed. This process
  takes a lot of time. C++ provides a solution of this
  problem, that is inline function. With inline function,
  the compiler replaces the function call statement
  with the function code itself (process called
  expansion) and then compiles the entire code.
  Thus, with inline functions, the compiler does not
  have to jump to another location to execute the
  function, and then jump back as the code of the
  called function is already available to the calling
  program.
Example to demonstrate inline functions
#include<iostream.h>
#include<conio.h>
inline float mul (float x, float y)
{
       return (x*y);
}
inline double div (double p, double q)
{
       return (p/q);
}
int main()
{
       float a = 12.345;
       float b = 9.82;
       clrscr();
cout<<mul (a,b)<<endl;
cout<<div (a,b)<<endl;
return 0;
}
Output
121.228
1.25713
Thank You

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

07. Virtual Functions
07. Virtual Functions07. Virtual Functions
07. Virtual Functions
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
Structure & union
Structure & unionStructure & union
Structure & union
 
Function in C program
Function in C programFunction in C program
Function in C program
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
 
functions of C++
functions of C++functions of C++
functions of C++
 
Friend function
Friend functionFriend function
Friend function
 
C function presentation
C function presentationC function presentation
C function presentation
 
Pointers, virtual function and polymorphism
Pointers, virtual function and polymorphismPointers, virtual function and polymorphism
Pointers, virtual function and polymorphism
 
Function overloading
Function overloadingFunction overloading
Function overloading
 
Constructors and Destructor in C++
Constructors and Destructor in C++Constructors and Destructor in C++
Constructors and Destructor in C++
 
Strings in C
Strings in CStrings in C
Strings in C
 
Managing input and output operation in c
Managing input and output operation in cManaging input and output operation in c
Managing input and output operation in c
 
Manipulators in c++
Manipulators in c++Manipulators in c++
Manipulators in c++
 
Operators in C++
Operators in C++Operators in C++
Operators in C++
 
Templates
TemplatesTemplates
Templates
 
Constructor and Types of Constructors
Constructor and Types of ConstructorsConstructor and Types of Constructors
Constructor and Types of Constructors
 
array of object pointer in c++
array of object pointer in c++array of object pointer in c++
array of object pointer in c++
 
pointers,virtual functions and polymorphism
pointers,virtual functions and polymorphismpointers,virtual functions and polymorphism
pointers,virtual functions and polymorphism
 
Types of function call
Types of function callTypes of function call
Types of function call
 

Similar a Functions in C++

Classes function overloading
Classes function overloadingClasses function overloading
Classes function overloading
ankush_kumar
 

Similar a Functions in C++ (20)

Functions in C++ (OOP)
Functions in C++ (OOP)Functions in C++ (OOP)
Functions in C++ (OOP)
 
Programming Fundamentals Functions in C and types
Programming Fundamentals  Functions in C  and typesProgramming Fundamentals  Functions in C  and types
Programming Fundamentals Functions in C and types
 
unit_2 (1).pptx
unit_2 (1).pptxunit_2 (1).pptx
unit_2 (1).pptx
 
Presentation on C language By Kirtika thakur
Presentation on C language By Kirtika thakurPresentation on C language By Kirtika thakur
Presentation on C language By Kirtika thakur
 
Functions IN CPROGRAMMING OF ENGINEERING.pptx
Functions IN CPROGRAMMING OF ENGINEERING.pptxFunctions IN CPROGRAMMING OF ENGINEERING.pptx
Functions IN CPROGRAMMING OF ENGINEERING.pptx
 
Object oriented programming system with C++
Object oriented programming system with C++Object oriented programming system with C++
Object oriented programming system with C++
 
Functions in C++ programming language.pptx
Functions in  C++ programming language.pptxFunctions in  C++ programming language.pptx
Functions in C++ programming language.pptx
 
unit_2.pptx
unit_2.pptxunit_2.pptx
unit_2.pptx
 
Functionincprogram
FunctionincprogramFunctionincprogram
Functionincprogram
 
C++ functions presentation by DHEERAJ KATARIA
C++ functions presentation by DHEERAJ KATARIAC++ functions presentation by DHEERAJ KATARIA
C++ functions presentation by DHEERAJ KATARIA
 
C++ Overview PPT
C++ Overview PPTC++ Overview PPT
C++ Overview PPT
 
C++
C++C++
C++
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
Functions and pointers_unit_4
Functions and pointers_unit_4Functions and pointers_unit_4
Functions and pointers_unit_4
 
Chapter 5
Chapter 5Chapter 5
Chapter 5
 
Function in c program
Function in c programFunction in c program
Function in c program
 
Lecture05
Lecture05Lecture05
Lecture05
 
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
 
Classes function overloading
Classes function overloadingClasses function overloading
Classes function overloading
 
C++ functions
C++ functionsC++ functions
C++ functions
 

Último

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
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 

Último (20)

FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
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
 
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
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
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
 
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.
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
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
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
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
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
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
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 

Functions in C++

  • 1. Functions in C+ + Presented by Sachin Sharma
  • 2. Function Overloading • C++ enables several functions of the same name to be defined, as long as these functions have different sets of parameters (at least as far as their types are concerned). This capability is called function overloading.
  • 3. Example To Use The concept of function overloading # include<iostream.h> # include<conio.h> void area (float r); void area (float l, float b); void main() { float r1, l1, b1; clrscr(); cout<<“ Enter value of r1: ”<<endl; cin>>r1; cout<<“ Enter value of l1: ”<<endl; cin>>l1; cout<<“ Enter value of b1: ”<<endl; cin>>b1; cout<<“ Area of the circle is “<<endl; area (r1); cout<<“ Area of the rectangle is “<<endl; area (l1, b1); } void area (float r) { float a = 3.14*r*r; cout<<“ Area = “<<a<<endl; } void area () { float a1 = l*b;
  • 4. Output Enter value of r1: 2 Enter value of l1: 4 Enter value of b1: 6 Area of the circle is Area = 12.56 Area of the rectangle is Area = 24
  • 5. Inline Functions in C++ • Whenever we call a function, control jump to function and come back to caller program when execution of function is completed. This process takes a lot of time. C++ provides a solution of this problem, that is inline function. With inline function, the compiler replaces the function call statement with the function code itself (process called expansion) and then compiles the entire code. Thus, with inline functions, the compiler does not have to jump to another location to execute the function, and then jump back as the code of the called function is already available to the calling program.
  • 6. Example to demonstrate inline functions #include<iostream.h> #include<conio.h> inline float mul (float x, float y) { return (x*y); } inline double div (double p, double q) { return (p/q); } int main() { float a = 12.345; float b = 9.82; clrscr(); cout<<mul (a,b)<<endl; cout<<div (a,b)<<endl; return 0; }