Pages

Write a program to add two numbers by using pointers in C++ language.

Friday, 21 February 2014

#include <iostream>
using namespace std;

int main()
{
    int a, b, *p1, *p2, sum;
    cout << "Enter both numbers: ";
    cin >> a >> b;
    p1 = &a;
    p2 = &b;
    sum = *p1 + *p2;
    cout << "Sum is " << sum <<endl;
    system("pause");
}

 

Search Box

Most Reading

Contact Form

Name

Email *

Message *