0% found this document useful (0 votes)
6 views

Inline Functions in CPP..

Uploaded by

radhikaj500
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Inline Functions in CPP..

Uploaded by

radhikaj500
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Inline Functions in C++

Inline functions are a C++ feature designed to optimize function calls by replacing
them with the actual function body at the point of call during compilation. This can
potentially improve performance by reducing function call overhead, which includes
saving the return address, pushing arguments onto the stack, and transferring
control to the function.

How Inline Functions Work:

Declaration:

1. The inline keyword is placed before the function declaration.


2. The function is typically defined within a header file to be accessible
to multiple source files.

Compilation:

1. The compiler replaces each function call with the actual function body.

Benefits:

1. Reduced function call overhead: This can lead to significant


performance improvements, especially for small functions that are
called frequently.
2. Improved code readability: By inlining simple functions, the code can
become more concise and easier to understand.

#include <iostream.h>
#include<conio.h>

inline int square(int x)


{
return x * x;
}

void main()
{
clrscr();
int num = 5;

int result = square(num);


cout << "Square of " << num << " is " << result << std::endl;

getch();
}

You might also like