Simple Program for Inline Function without Class Using C++ Programming


In various versions of the C and C++ programming languages, an inline function is a function upon which the compiler has been requested to perform inline expansion. In other words, the programmer has requested that the compiler insert the complete body of the function in every place that the function is called, rather than generating code to call the function in the one place it is defined. Compilers are not obligated to respect this request.

For Better Understanding,

Syntax Of Inline Function

inline return_type function_name(arguments...)

Simple Program for Inline Function without Class


using namespace std;

// Inline function without class
inline float cube(float x) {
    return (x * x * x);

int main() {
    float val1, val2;

    cout << "Enter two values:";
    cin >> val1>>val2;

    cout << "\n\nCube value for val1 is          :" << cube(val1) << endl;
    cout << "\n\nCube value for val2 is          :" << cube(val1) << endl;

Sample Output

Enter two values:5

Cube value for val1 is          :125
Cube value for val2 is          :125