Pointer as function return in C plus plus programming language

Author: Al-mamun Sarkar Date: 2020-04-03 17:29:55

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