Saved Bookmarks
| 1. |
Define inline functions in C and C ++. Also, give an example of an inline function in C. |
|
Answer» An inline function in C or C++ is one that is declared with the keyword "inline". It serves two purposes:
An example of an inline function in C is given below: inline void addNumbers(INT a, int b){ int ans = a + b; printf("SUM of the two numbers is: %d", ans);}Let us say that the above inline function is called somewhere in the main function of the C program as: int x = 10;int y = 20;addNumbers(x, y);Here, the "addNumbers(x, y);" function call will be replaced by the following piece of code in the main function itself by the compiler: int x = 10;int y = 20;int ans = x + y;printf("Sum of the two numbers is: %d", ans); |
|