Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Summary

Summary Inline function in c++

Rating
-
Sold
-
Pages
1
Uploaded on
22-05-2023
Written in
2022/2023

This document describes the medhod of inline functions in c++. It is explained with a clear syntax and a simple example tance of inline functions is highlighted.

Institution
Course

Content preview

Inline Functions in C++

Inline functions are used to reduce the compilation time runtime and make programs faster.
When a function is inline, the compiler places a copy of the specified function's code at each
point where the function is called at compile time. This helps reduce the overhead of control
transfer, which can slow down the program. The syntax for using inline functions is to place the
keyword "inline" before the return type of the function, followed by the function name, and then
the parameters and function definition inside parentheses.

Example:
Here's an example of how to use an inline function in C++. First, define the function using the
"inline" keyword before the return type. In this example, we define a function called "triple" that
takes in a number and returns the triple of that number.

using namespace std;
inline int triple(int num){
return num*3;
}

Then, in the main logic, we can call this function using the function name and passing in a
number. For instance, if we pass in 3, we would expect to get 9 as the output.

int main(){
int result = triple(3);
cout << result << endl;
return 0;
}

Without using inline, the compiler would have to move back and forth between the main logic
and the function definition, which can slow down the program. But with inline, the function
definition is copied into the main logic, reducing the overhead of control transfer and making the
program faster.

Written for

Institution
Course

Document information

Uploaded on
May 22, 2023
Number of pages
1
Written in
2022/2023
Type
SUMMARY

Subjects

$8.89
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
sivahitler0707

Get to know the seller

Seller avatar
sivahitler0707 Skacas
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
2 year
Number of followers
0
Documents
1
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions