Add two numbers using pointers - C++ Program

Q. Write a C++ program to display the addition of two numbers using pointer.

Answer:

Following program is performing an addition of two numbers using pointer.

#include<iostream>
using namespace std;
int main()
{
        int num1, num2, *ptr1, *ptr2, sum=0;
        cout<<"\n Enter Two Numbers : \n";
        cout<<" ";
        cin>>num1;
        cout<<" ";
        cin>>num2;
        ptr1 = &num1;
        ptr2 = &num2;
        sum = *ptr1 + *ptr2;
        cout<<"\n Addition of Two Numbers : "<<sum;
        return 0;
}


Output:

addition using pointers