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++.
#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 << "Sum is:" << s;
return 0;
}
Output:
Enter two numbers:10 20
Sum is:30