C Inline Functions

Inline functions are those functions whose function declaration contains the inline keyword. The Inline keyword suggests the compiler to replace the function call with the body of the inline function. Compiler may or may not perform function substitution.

Syntax

inline function-name (parameters)
{
    //A short or single line body
}

Example Code

#include<stdio.h>

//static is required to force the compiler to consider this function in the linker.
static inline int max(int x, int y) 
{ 
    return (x > y) ? x : y; 
} 
  
int main(void) 
{ 
    int getmax; 
  
    // inline function call 
    getmax = max(10,20); 
  
    printf("Max of 10 and 20 is: %d\n", getmax); 
    
    return 0;
}

Output

Max of 10 and 20 is: 20

Trending

C Programming

Remember to follow community guidelines and don't go off topic.