Differences between the inline function and the normal function in C++The function is a block of reusable code that performs a particular task. It is defined and called for from different sections of the program. In C++, the functions are divided into many types based on their usage and features. These are Regular functions, Inline functions, Recursive functions, Friend functions, Virtual functions, Lambda functions, etc. These functions are essential for organizing and structuring the code and making the entire program maintainable. Normal function:Regular or normal functions are the most common functions in C++. They are defined outside of any class and have a separate block of code called when the function is invoked. When the normal function is called, the compiler creates a new stack frame for the functions to track the function calls. This function has a return type. It will return some value after doing computation. It takes some values whenever it is called. Those values are generally called arguments. The function will work on those arguments and return the output. There will be no return type for some normal functions, which means those have a void return type. Syntax of the Normal Function:It has the following syntax: The return type specifies the type of the value the function returns. Parameters are input to the function, which are always present in parentheses. The function code is written in {}. The return is used to give output to the function, which is called. Example:Let us take a C++ program to illustrate the normal functions: Output: Inline function:Inline functions are special types of functions in C++. Which are small, frequently used code snippets. These are directly inserted into the code at the point where they are called are called inline functions. The compiler will replace the function call with the actual code at the call site for performance optimization. So here, the new stack frame is not created for the function or jumps to a separate block of code. It will help to improve the performance. Syntax of the Inline function:It has the following syntax: The keyword "inline" is used to use the inline function. The return type is not mandatory. Parameters are input values of the function. Example:Let us take a C++ program to illustrate the inline functions: Output: Similarities between the inline function and normal function:There are several similarities between the inline and normal functions. Some main similarities between the inline and normal functions are as follows:
Differences between the inline functions and normal functions:There are several differences between the inline and normal functions. Some main differences between the inline and normal functions are as follows:
Next TopicEdmonds Karp Algorithm in C++ |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India