inline functions in c++
DESCRIPTION
Inline functions in c++ Index- What is inline function? Why use inline function? When to use inline function? How to make a normal function, inline? Inline is a request or command?TRANSCRIPT
![Page 1: Inline functions in c++](https://reader036.vdocument.in/reader036/viewer/2022082603/54838495b4af9f8a068b4576/html5/thumbnails/1.jpg)
Inline functions in C++
Presented by Harish Gyanani
![Page 2: Inline functions in c++](https://reader036.vdocument.in/reader036/viewer/2022082603/54838495b4af9f8a068b4576/html5/thumbnails/2.jpg)
Index (Questions answered in this ppt)
• What is inline function?• Why use inline function?• When to use inline function?• How to make a normal function, inline?• Inline is a request or command?
![Page 3: Inline functions in c++](https://reader036.vdocument.in/reader036/viewer/2022082603/54838495b4af9f8a068b4576/html5/thumbnails/3.jpg)
What is inline function?
• An inline function is a function that is expanded in line when it is invoked.
• The compiler replaces the function call with the corresponding function code.
• If a function is inline, the compiler places a copy of the code of that function at each point where the function is called at compile time.
![Page 4: Inline functions in c++](https://reader036.vdocument.in/reader036/viewer/2022082603/54838495b4af9f8a068b4576/html5/thumbnails/4.jpg)
Why use inline function?
To eliminate the cost of calls to small functions, we use inline function.
![Page 5: Inline functions in c++](https://reader036.vdocument.in/reader036/viewer/2022082603/54838495b4af9f8a068b4576/html5/thumbnails/5.jpg)
When to use?
The functions are made inline when they are small enough to be defined in one or two lines.
![Page 6: Inline functions in c++](https://reader036.vdocument.in/reader036/viewer/2022082603/54838495b4af9f8a068b4576/html5/thumbnails/6.jpg)
How to make a normal function inline?
It is easy to make a function inline. All we need to do is to prefix the keyword inline to the function definition. All inline functions must be defined before they are called.
![Page 7: Inline functions in c++](https://reader036.vdocument.in/reader036/viewer/2022082603/54838495b4af9f8a068b4576/html5/thumbnails/7.jpg)
Inline is a request, not a command
The inline keyword merely sends a request, not a command, to the compiler. The compiler may ignore this request if the function definition is too long or too complicated and the function as a normal function.