Tuesday 13 February 2018

Inline function in C++

Inline function is a function which is expanded at a particular line when it is called.
We must keep inline functions small because small inline functions have better efficiency
All the member functions defined inside the class definition are by default declared as Inline
To declare a function as inline, use the keyword inline before the function name.
It is used to increase the execution time of a program.
Inline functions are used to improve performance of the application.
If a function is declared as inline, the compiler places a copy of the code of that function at each point where the function is called at compile time. Many inline functions can lead your program to grow up in size so that only small functions are declared as inline.
Advantages
It makes the program faster.
Syntax
 Inline  return_type  function_name()
{
  //function body
}
Example:
#include<iostream.h>
#include<conio.h>
inline void display()   //function definition
{
  cout<<"Welcome to learningPoint92";
}

void main()
{
 display();  // function Call
getch();
}
Output:
Welcome to learningPoint92



No comments:

Post a Comment

apply function in R

1) apply function: It takes 3 arguments matrix,margin and function.. Example: m<-matrix(c(1,2,3,4),nrow=2,ncol=2) m #1 indicates it is ap...