Saved Bookmarks
| 1. |
In C and C++, define inline functions. Also, show how to use an inline function in C. |
|
Answer» In C or C++, an inline function is one that is declared using the keyword "inline." It has two important features:
An example of an inline function in C is given below: inline VOID multiply(int x, int y){ int answer = x * y; printf("Product of x and y is the following: %d", answer);}Let us assume that the above written inline function will be called inside the main function of the C program as follows: int xval = 5;int yval = 4;multiply(xval, yval);Here, the "multiply(xval, yval);" function call is going to be replaced in the main function itself by the compiler by the piece of code given below: int xval = 5;int yval = 4;int answer = xval * yval;printf("Product of x and y is the following: %d", answer); |
|