Find jobs | Company-wise jobs
Jobseekers | Employer login
About us Sitemap of www.CareerRide.com Sitemap FAQ related with www.CareerRide.com FAQ Click here to Contact us Contact
       
Submit Resume Free ! | Access Resume Free !
Home Interview Q&A Tutorials .NET Java Soft skills CV GD Work from home IT practice test MBA practice test FAQs in PDF Books Jobs FAQs
Interview questions                  
C++ interview
C interview
C test!
C++ test!
Data structure test!
C++ access control
C++ COM
C++ constructors destructors
C++ containers
C++ DCOM
C++ derived class
C++ error handling
C++ exception handling
C++ friend members
C++ inheritance
C++ inline function
C++ memory leaks
C++ namespaces
C++ new and delete
C++ operator overloading
C++ pointers
C++ references
C++ static data
C++ syntax
C++ template
C++ type checking
C++ virtual functions
C++ pure virtual functions
C++ as an object-oriented
More concept of C++
C++ data types
C++ control constructs
C++ collections
C++ functions
C++ arrays
C++ C-string
C++ classes and structure
C++ Friend functions & classes
C++ polymorphism
C++ multiple inheritance
C++ function template
C++ class templates
C++ standard stream class
ATL server
Data structure in C++
 

What is inline function?

<<Previous  Next>>

C++  - What is inline function? - Jan 07, 2009 at 18:10 PM by Anuja Changede

What is inline function?  

An inline function is a combination of macro & function. At the time of declaration or definition, function name is preceded by word inline.

When inline functions are used, the overhead of function call is eliminated. Instead, the executable statements of the function are copied at the place of each function call. This is done by the compiler.

Consider following example:

#include <iostream>
using namespace std;

inline int sqr(int x)
{
           int y;
           y = x * x;
           return y;
}
int main()
{
               int a =3, b;
               b = sqr(a);
               cout <<b;
               return 0;
}

Here, the statement b = sqr(a) is a function call to sqr(). But since we have declared it as inline, the compiler replaces the statement with the executable stmt of the function (b = a *a)

Please note that, inline is a request to the compiler. If it is very complicated function, compiler may not be able to convert it to inline. Then it will remain as it is. E.g. Recursive function, function containing static variable, function containing return statement or loop or goto or switch statements are not made inline even if we declare them so.

Also, small functions which are defined inside a class (ie their code is written inside the class) are taken as inline by the compiler even if we don’t explicitly declare them so. They are called auto inline functions.

C++  - Define Inline Function - Feb 09, 2009 at 23:10 PM

Define Inline Function.

Answer - When the function is defined Inline, the C++ compiler puts the function body inside the calling function. You can define function as Inline when the function body is small and need to be called many times, thus reduces the overhead in calling a function like passing values, passing control, returning values, returning control.

Also read

Explain the advantages of inline functions.

It relieves the burden involved in calling a function. It is used for functions that need fast execution..............

What happens when recursion functions are declared inline?

The call to the body of the function is replaced by an inline function. This reduces the saving context on stack overhead. This process is efficient when the size of the function is small and invoked................

Do inline functions improve performance. Explain.

Inline functions behave like macros. When an inline function gets called, instead of transferring the control to the function.................

<<Previous  Next>> 

 

 
Want to be hunted by potential employers? Just submit your key skills!

Popular FAQs

.NET .Net Architecture ADO.NET Java Oracle C#.NET
VB.NET DOT.NET AJAX ASP.NET NET Framework OOPS in .NET
C++ Sql Server Data warehousing EJB MySQL Linux
PHP UML Networking Testing XML  
 
Copyright © 2008 - 2010 CareerRide.com. All rights reserved.