To create an in-line function, precede its definition with the inline keyword. For example, in this program, calls to the function max( ) are optimized: - C Function

C examples for Function:Function Definition

Description

To create an in-line function, precede its definition with the inline keyword. For example, in this program, calls to the function max( ) are optimized:

Demo Code

#include <stdio.h>

inline int max(int a, int b)
{
   return a > b ? a : b;
}

int main(void)
{
   int x = 5, y = 10;

   printf("Max of %d and %d is: %d\n", x, y, max(x, y));

   return 0;/*from   ww w  .j  a v a2 s.  c o m*/
}

Result

For a typical implementation of inline, the preceding program is equivalent to this one:

Demo Code

#include <stdio.h>

int main(void)
{
   int x = 5, y = 10;

   printf("Max of %d and %d is: %d\n", x, y, (x>y ? x : y));

   return 0;//w  w  w .java2  s  . c om
}

Result


Related Tutorials