SlideShare uma empresa 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

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

Introduction to c++
Introduction to c++Introduction to c++
Introduction to c++
 
Call by value or call by reference in C++
Call by value or call by reference in C++Call by value or call by reference in C++
Call by value or call by reference in C++
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
Functions in c
Functions in cFunctions in c
Functions in c
 
C++
C++C++
C++
 
Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c language
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
C++
C++C++
C++
 
SPL 9 | Scope of Variables in C
SPL 9 | Scope of Variables in CSPL 9 | Scope of Variables in C
SPL 9 | Scope of Variables in C
 
Introduction to c++ ppt 1
Introduction to c++ ppt 1Introduction to c++ ppt 1
Introduction to c++ ppt 1
 
Operators in C/C++
Operators in C/C++Operators in C/C++
Operators in C/C++
 
Function in C
Function in CFunction in C
Function in C
 
Unit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in cUnit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in c
 
C++ Programming Language
C++ Programming Language C++ Programming Language
C++ Programming Language
 
C functions
C functionsC functions
C functions
 
Function overloading
Function overloadingFunction overloading
Function overloading
 
07. Virtual Functions
07. Virtual Functions07. Virtual Functions
07. Virtual Functions
 
Pointer in C++
Pointer in C++Pointer in C++
Pointer in C++
 
Intro to c++
Intro to c++Intro to c++
Intro to c++
 
Arrays in c unit iii chapter 1 mrs.sowmya jyothi
Arrays in c unit iii chapter 1 mrs.sowmya jyothiArrays in c unit iii chapter 1 mrs.sowmya jyothi
Arrays in c unit iii chapter 1 mrs.sowmya jyothi
 

Semelhante a Functions in C++

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

Semelhante 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
 
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
 
Functions struct&union
Functions struct&unionFunctions struct&union
Functions struct&union
 

Último

The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 

Último (20)

Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).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.
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptx
 
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
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
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
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
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
 

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; }