Simple Program for Inline Function Without Class
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.
- Declare the variables that hold the program’s data.
- Read the input values that the program will work with.
- 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.
Related Pages
Learn the concept first, then study the code:
- C++ Programs — Browse all C++ Programs.