c / intermediate
Snippet
Inline Functions for Optimization
The 'inline' keyword suggests to the compiler that it should replace the function call with the actual code of the function. This reduces the overhead of a function call (like pushing arguments to the stack), which can improve performance in tight loops.
snippet.c
1
2
3
4
5
6
7
8
9
10
11
#include <stdio.h>inline int square(int x) {return x * x;}int main() {int val = 5;printf("Square of %d is %d\n", val, square(val));return 0;}
Breakdown
1
inline int square(int x)
Declares an inline function to suggest expansion at the call site.
2
return x * x;
The logic that will be embedded directly where the function is called.