C++ Program to display the cube of the number upto a given integer using Inline function.
Write C++ Program to display the cube of the number upto a given integer using Inline function.
The inline function Inline T4Tutorials::T4Tutorials_function()
helps to increase the execution time of a program. The programmer can make a request to the compiler to make the inline function as Inline T4Tutorials::T4Tutorials_function()
.
Making inline means that compiler can replace the function definitions of Inline T4Tutorials::T4Tutorials_function()
with the place where this function is called obj.T4Tutorials_function();
.
The compiler replaces the definition of inline functions at compile time instead of referring function definition at runtime.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | #include<iostream> using namespace std; class T4Tutorials { private: int i,n; public: int T4Tutorials_function(); }; inline T4Tutorials::T4Tutorials_function() { cout<<"Please enter the number :"<<endl; cin>>n; for(i=1; i<=n; i++) { cout<<"The cube of"<<i<<"is ="<<(i*i*i)<<endl; } } int main() { T4Tutorials obj; obj.T4Tutorials_function(); } |
Output
Please enter the number:
4
cube of 1 is: 1
cube of 2 is: 8
cube of 3 is: 27
cube of 4 is: 64