C++ Program using pointers with structure
In this program, You will learn how to implement pointers with the structure in C++.
struct Test *ptr, t;
Example: How to implement pointers with the structure in C++.
#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 << "x value is:" << (*ptr).x;
cout << "\ny value is:" << ptr->y;
return 0;
}
Output:
x value is:10
y value is:20