Pointer as function return in C plus plus programming language.The following code shows how to return pointer from a function in C plus plus Programming Language.
Code:
#include<iostream>
using namespace std;
int *sum (int *a, int *b)
{
int *c = new int;
*c = *a + *b;
return c;
}
int main()
{
int a = 10, b = 15;
int *total = sum(&a, &b);
cout << "Total is : " << *total;
return 0;
}
Output:
Total is : 25