Inline Functions in C

Ordinarily, calling a function causes the computer to save its current instruction address, jump to the function called and execute it, then make the return jump to the saved address. With small functions that you need to call often, this can degrade the program’s run-time behavior substantially. As a result, C99 has introduced the option of defining inline functions. The keyword inline is a request to the compiler to insert the function’s machine code wherever the function is called in the program. The result is that the function is executed as efficiently as if you had inserted the statements from the function body in place of the function call in the source code.
To define a function as an inline function, use the function specifier inline in its definition.


// type and declaration of function is defined first if function is 
// other than of integer type
void square(int*);  // void type, so declaration is compulsory
// paramater of type to integer to pointer
int main( ) 
    int num;
    printf("Enter number ");
    square(&num); // calling function square refering by address of num (& num)
    printf("number after modification %d",num); // value of num is not affected
    return 0;

inline void square(int *number) // inline keyword for making function inline
    // value modified locally, no effect to passed value
    *number = *number + 10;
    printf("local value %d\n",*number);

You may also like...