C++ Program to add two numbers using pointers


In this program, You will learn how to add two numbers using pointers in C++.


10 + 10 = 20

20 + 10 = 30


Example: How to add two numbers using pointers in C++

Run it Now
#include<iostream>
using namespace std;

int main() {

    int x, y, s;
    int *a, *b;

    cout << "Enter two Numbers :";
    cin >> x>>y;

    a = &x;
    b = &y;
    s = (*a) + (*b);

    cout << "\nSum is :" << s;

    return 0;
}

Output:

Enter two Numbers :10 20
Sum is :30