C++ Program using pointers with structure


In this program, You will learn how to implement pointers with structure in C++.


struct Test *ptr, t;


Example: How to implement pointers with structure in C++

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

struct Test {
    int x, y;
};

int main() {

    struct Test *ptr, t;

    ptr = &t;

    (*ptr).x = 10;
     //OR
    ptr->y = 20;

    cout << "\nThe x value is :" << (*ptr).x;
    cout << "\nThe y value is :" << ptr->y;

    return 0;
}

Output:

The x value is :10
The y value is :20