Fixed syntax error. (#27164)
* Fixed syntax error. Fixed a syntax error in line 55. Also corrected the indentation. * Update index.md
This commit is contained in:
committed by
Manish Giri
parent
44661a3e06
commit
a43d6c6daf
@ -6,7 +6,7 @@ title: Inline Functions in C++
|
||||
|
||||
When the program executes the function call instruction, the CPU stores the memory address of the instruction following the function call, copies the arguments of the function on the stack, and finally transfers control to the specified function. The CPU then executes the function code, stores the function return value in a predefined memory location/register and returns control to the calling function. This can become overhead if the execution time of function is less than the switching time from the caller function to called function (callee). For functions that are large and/or perform complex tasks, the overhead of the function call is usually insignificant compared to the amount of time the function takes to run. However, for small, commonly-used functions, the time needed to make the function call is often more than the time needed to actually execute the function’s code. This overhead occurs for small functions because execution time of small function is less than the switching time.
|
||||
|
||||
C++ provides an inline functions to reduce the function call overhead for small functions. An inline function substitutes the code of the function where the call is being made (inline) instead of passing to the function. This substitution is performed by the C++ compiler at compile time.
|
||||
C++ provides inline functions to reduce the function call overhead for small functions. An inline function substitutes the code of the function where the call is being made (inline) instead of passing to the function. This substitution is performed by the C++ compiler at compile time.
|
||||
|
||||
The syntax for defining the function inline is:
|
||||
|
||||
@ -52,7 +52,7 @@ int main(){
|
||||
|
||||
MathOperation obj;
|
||||
|
||||
cout << "Addition is :" << obj.add(34,12) << <"\n";
|
||||
cout << "Addition is :" << obj.add(34,12) << "\n";
|
||||
cout << "Division is :" << obj.div(12,3.4) << "\n";
|
||||
|
||||
return 0;
|
||||
@ -124,8 +124,8 @@ inline void operation :: product()
|
||||
|
||||
inline void operation ::division()
|
||||
{
|
||||
div=a/b;
|
||||
cout<<"Division of two numbers: "<<a/b<<"\n" ;
|
||||
div = a/b;
|
||||
cout << "Division of two numbers: " << a/b << "\n" ;
|
||||
}
|
||||
|
||||
int main()
|
||||
|
Reference in New Issue
Block a user