13B Lecture Notes - Inline Function, Compile Time

7 views1 pages
Department
Course
Professor

Document Summary

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. Here"s an example of how to use an inline function in c++. 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.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents

Related Questions