0

What is inline function ? Explain with an example.

5th Dec 2016, 1:17 AM
Sumita
Sumita - avatar
3 ответов
+ 3
The inline functions are a C++ enhancement feature to increase the execution time of a program. Functions can be instructed to compiler to make them inline so that compiler can replace those function definition wherever those are being called. Compiler replaces the definition of inline functions at compile time instead of referring function definition at runtime. Using the inline keyword is simple, just put it before the name of a function. Then, when you use that function, pretend it is a non-inline function: #include <iostream> using namespace std; inline void hello() { cout<<"hello"; } int main() { hello(); //Call it like a normal function return 0; } However, once the program is compiled, the call to hello(); will be replaced by the code making up the function. So the main() will look like this sfter the compile: int main() { cout<<"hello"; return 0; }
5th Dec 2016, 1:26 AM
Ripper
Ripper - avatar
0
Whats the use of the inline function....where will this be tangible or important..?
28th Aug 2019, 2:06 AM
cerebrocerberus
cerebrocerberus - avatar
- 1
compiler treat inline function as a single statement..& that's the reason it reduces the execution time...
5th Dec 2016, 1:34 AM
Rahul Sharma
Rahul Sharma - avatar