Home > Backend Development > C++ > In C language, what is an inline function?

In C language, what is an inline function?

WBOY
Release: 2023-09-08 11:21:09
forward
1225 people have browsed it

In C language, what is an inline function?

Inline functions can be replaced where the function call occurs. Function substitution is always the compiler's choice.

  • In an inline function, the function call is replaced by the actual program code.

  • Most inline functions are used for small calculations. They are not suitable for large calculations.

  • Inline functions are similar to ordinary functions. The only difference is that we put a keyword inline before the function name.

Inline functions are created using the following syntax -

inline function_name (){
   //function definition
}
Copy after login

Example

The following are inline functions for a C program:

Live Demo

-->
#include<stdio.h>
inline int mul(int a, int b) //inline function declaration{
   return(a*b);
}
int main(){
   int c;
   c=mul(2,3);
   printf("Multiplication:%d</p><p>",c);
   return 0;
}
Copy after login

Output

When the above program is executed, the following results will be produced-

6
Copy after login

The above is the detailed content of In C language, what is an inline function?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template