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 diff...
Example To Use The concept of function                  overloading# include<iostream.h># include<conio.h>void area (float...
OutputEnter value of r1:2Enter value of l1:4Enter value of b1:6Area of the circle isArea = 12.56Area of the rectangle isAr...
Inline Functions in C++• Whenever we call a function, control jump to  function and come back to caller program when  exec...
Example to demonstrate inline functions#include<iostream.h>#include<conio.h>inline float mul (float x, float y){       ret...
Output121.2281.25713
Thank You
Upcoming SlideShare
Loading in...5
×

Functions in C++

4,020

Published on

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
4,020
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
206
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Functions in C++

  1. 1. Functions in C+ + Presented by Sachin Sharma
  2. 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. 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. 4. OutputEnter value of r1:2Enter value of l1:4Enter value of b1:6Area of the circle isArea = 12.56Area of the rectangle isArea = 24
  5. 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. 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;}
  7. 7. Output121.2281.25713
  8. 8. Thank You
  1. ¿Le ha llamado la atención una diapositiva en particular?

    Recortar diapositivas es una manera útil de recopilar información importante para consultarla más tarde.

×