Site icon T4Tutorials.com

C++ Pointers, and user define function in a single program

Write a C++ program having concept of Pointers, and user define function in a single program.

#include<iostream>
using namespace std;

int add(int* x, int* y) {
    return *x + *y;
}

int main() {
    int A, B, sum;
    
    cout << "Please enter the First Number  : "<<endl;
    cin >> A;
    
    cout << "Please enter the Second Number : "<<endl;
    cin >> B;
    
    sum = add(&A, &B);
    cout << "Sum of Two Numbers " << A <<" and " << B << " = " << sum;
    
    return 0;
}

Output

Please enter the First Number :
7
Please enter the Second Number :
3
Sum of Two Numbers 7 and 3 = 10

Exit mobile version