0% found this document useful (0 votes)
6 views20 pages

2. Functions and Function Overloading

The document discusses functions in programming, focusing on components, parameters, and the return statement. It explains function overloading, static local variables, and the use of reference variables as parameters. Additionally, it covers inline functions and provides an example of using an inline function in C++.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views20 pages

2. Functions and Function Overloading

The document discusses functions in programming, focusing on components, parameters, and the return statement. It explains function overloading, static local variables, and the use of reference variables as parameters. Additionally, it covers inline functions and provides an example of using an inline function in C++.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 20

Functions &

Function
Overloading
MARIYA TAUQEER
Components of a function
Function using
loop
Functions with parameters
Passing data by value
The return
statement

Causes a
function to end
immediately
Static local variables

If a function is called
more than once in a
program the values
stored in the function’s
local variables don't
persist between
function calls.
Local variables are
destroyed when the
function terminates
and then recreated
when the function
starts again.
Static variables
are not
destroyed
when the
function
returns
Using reference variables as
parameters
Reference variable allows a function to access the parameter’s original argument. Changes to
the parameter are also made to the argument.
The ampersand must
appear in both the
prototype and the
header of any function
that uses a reference
variable as a parameter.
It does not appear in
the function call
Overloading functions
Two or more functions may have the same name as long as their parameter
lists are different.
Different number of arguments
Inline Functions
To save execution time in short functions, you may elect to put the code in the function body
directly inline with the code in the calling program. That is, each time there’s a function call in
the source file, the actual code from the function is inserted, instead of a jump to the function.

C++ inline function is powerful concept that is commonly used with classes. If a function is
inline, the compiler places a copy of the code of that function at each point where the function
is called at compile time.
#include <iostream>
using namespace std;
inline int Max(int x, int y)
{
return (x > y)? x : y;
}
// Main function for the program
int main() { Output:
Max (20,10): 20
cout << "Max (20,10): " << Max(20,10) Max (0,200): 200
<< endl; cout << "Max (0,200): " << Max (100,1010): 1010
Max(0,200) << endl; cout << "Max
(100,1010): " << Max(100,1010) <<
endl;
return 0;
}

You might also like