Using Pointer in a Cube Function

#include <iostream>
using namespace std;
int main()
{
    int cubeval(int *);
    int v=5;
    cout<<"Real value of v is: "<<v<<endl;
    cubeval(&v);
    cout<<"Cube value of v is: "<<v<<endl;
    system("pause");
    return 0;
}
int cubeval(int *p)
{
    *p=*p* *p* *p;
    return *p;
}
The output is given below:
Real value of v is: 5
Cube value of v is: 125

0 comments:

Post a Comment