Skip to main content

Simple Program for Inline Function Without Class

2 min read Updated June 30, 2026
Share:
On this page (8sections)

Definition

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...)
{
  //function_code
  return_value;  
}

Simple Program for Inline Function without Class

#include<iostream>
#include<conio.h>

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;
    getch();
}

Sample Output

Enter two values:5
6

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

How It Works

This C++ program demonstrates Simple Program for Inline Function Without Class. It first reads the required values as input, then performs the core operation step by step, and finally prints the output shown in the Sample Output above.

  1. Declare the variables that hold the program’s data.
  2. Read the input values that the program will work with.
  3. Print the final result to the console so you can compare it with the sample output.

Try changing the input values and re-running the program to see how the output changes — this is the fastest way to understand how the logic behaves.

Learn the concept first, then study the code:

Frequently Asked Questions

What does this C++ program do?
It is a C++ example program that demonstrates Simple Program for Inline Function Without Class, including the complete source code and the expected sample output.
How do I compile and run this C++ program?
Save the code in a `.cpp` file, compile it with `g++ filename.cpp -o program`, then run it with `./program` (or `program.exe` on Windows).
What concepts does this example use?
This example uses reading user input and user-defined functions, illustrating a common pattern in C++ programming.

Related Tutorials

Search tutorials