C++ Program to add two numbers using pointers with structure


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


20 = 10 + 10

50 = 30 + 20


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

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

struct Test {
    int x, y, z;
};

int main() {

    struct Test *ptr, t;
    ptr = &t;

    cout << "Enter Two Numbers :";
    cin >> ptr->x >> ptr->y;

    ptr->z = ptr->x + ptr->y;
    cout << "\nThe Sum is :" << ptr->z;

    return 0;
}

Output:

Enter Two Numbers :10 20
The Sum is :30