C++ Program to find sum of two numbers using pointer returning functions
Program
#include<iostream>
using namespace std;
int * sum(int *x, int *y)
{
int *res = new int;
*res = *x + *y;
return res;
}
int main()
{
int x, y;
cout << "Enter the value of x and y:" << endl;
cin >> x >> y;
int *res = sum(&x, &y);
cout << "Sum = " << *res << endl;
return 0;
}
Output
Enter the value of x and y:
7
12
Sum = 19