Académique Documents
Professionnel Documents
Culture Documents
FUNCTION AND
INLINE
FUNCTION
2
POINTS
FUNCTION
INLINE FUNCTION
DIFFERENCE BETWEEN FUNCTION AND
INLINE FUNCTION
CONCLUSION
3
FUNCTION
DEFINITION:
How to declare a
function?
FUNCTION DECLARATION
FUNCTION CALL
FUNCTION DEFINITION
6
SYNTAX
void add( ); //function declaration
main( )
{
----------
add( ); //function call
----------
}
void add( ) // function definition
{
-----------------
}
7
1.Call by value
2.Call by reference
8
CALL BY VALUE
In this arguments are passed
by value this means that called function is given
values of the arguments in temporary variables
rather than originals. In this case, the changes
made to the parameter have no effect on the
argument.
CALL BY REFERENCE
In this method the address of an
argument is copied to the parameter. Inside the
subroutine , the address is used to access the
actual parameter in the call. Here the changes to
parameter affect argument.
NEED OF FUNCTION IN
PROGRAM
what is macro?
Inline Function
DEFINITION:
In C++,the functions that are not
actually called, rather their code is expanded in
line at the point of each invocation such
functions are called as inline functions.
14
SYNTAX
prototype fun_name( ); //function declaration
main( )
{
--------------------------
fun_name( ); //function call
}
inline prototype fun_name( );
//function definition
{
-------
}
15
When to use ?
Function can be made as inline as per programmer
need. Some useful recommendation are mentioned
below-
Program
#include <iostream>
using namespace std;
Program
#include <iostream.h>
using namespace std;
inline int Max(int x, int y) //defined function as inlined
{
return (x > y)? x : y;
}
int main( ) // Main function for the program
{
cout << "Max (20,10): " << Max(20,10) << endl;
cout << "Max (0,200): " << Max(0,200) << endl;
cout << "Max (100,1010): " << Max(100,1010) << endl;
return 0;
}
22
Max (20,10): 20
Max (0,200): 200
Max (100,1010): 1010
23