C examples for Function:Function Definition
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:
#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*/ }
For a typical implementation of inline, the preceding program is equivalent to this one:
#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 }