Inline function in C ++
Inline functions in C ++ are powerful concepts that are commonly used with classes. If a function is inline, the compiler places a copy of the code of that function at each location that the function is called at compile time.
Any changes to an inline function may require all guests of that function to be recompiled because the compiler will need to replace all the code again, otherwise it will continue with the old feature. .
To make a function is inline, place the inline keyword before the function name and the function definition before any call is created with that function. Compiler can ignore the inline identifier in case the function is defined as more than one line.
A function definition in a class definition is an inline function definition, even if an inline identifier is not used.
The following is an example to use the inline function to return the maximum value of two numbers:
#include using namespace std ; inline int Max ( int x , int y ) { return ( x > y )? x : y ; } // ham main cua chuong trinh int main ( ) { cout << "Gia tri lon nhat cua (30,20) la: " << Max ( 30 , 20 ) << endl ; cout << "Gia tri lon nhat cua (15,10) la: " << Max ( 15 , 10 ) << endl ; cout << "Gia tri lon nhat cua (120,1230) la: " << Max ( 120 , 1230 ) << endl ; return 0 ; }
Compiling and running the above C ++ program will produce the following results:
Gia tri lon nhat cua ( 30 , 20 ) la : 30 Gia tri lon nhat cua ( 15 , 10 ) la : 15 Gia tri lon nhat cua ( 120 , 1230 ) la : 1230
According to Tutorialspoint
Previous lesson: Friend function in C ++
Next article: Cursor this in C ++
You should read it
- How to turn on/off Inline AutoComplete in File Explorer address bar on Windows 11
- Display (inline-block) properties in CSS
- Block and inline elements in HTML
- Searching in IE8 pages gives results faster
- Save time with these text formatting functions in Microsoft Excel
- Function in programming C
- DAY function in SQL Server
- MIN function in SQL Server
- MAX function in SQL Server
- Style HTML with CSS
- SUM function in SQL Server
- The ord () function in Python
Maybe you are interested
How to turn a photo into a painting using the Generative Fill function in Photoshop
How to use the TREND function in Excel
Google Sheets Functions to Simplify Your Budget Spreadsheets
Instructions for using the TRIMRANGE function to clean up Excel tables
How to master numerical data in Google Sheets with the AVERAGE function
Don't buy headphones if they lack this important function!