Define pointer for structure : structure pointer « Structure « C++ Tutorial






#include <iostream>
using namespace std;

struct MyStructure
{
   int n;
   float f;
   float f2;
};

int main()
{ 
 MyStructure myMyStructure;
 MyStructure *ptrMyStructure;

 //set the f of the structure
 myMyStructure.f = 1000;

 //intialize the pointer
 ptrMyStructure = &myMyStructure;

 //change the pointers f
 ptrMyStructure->f = 2000;

 //print out the structures f
 cout << myMyStructure.f << "\n";

 return 0;
}
2000








8.4.structure pointer
8.4.1.Define pointer for structure
8.4.2.Pointers to structures
8.4.3.Use -> for structure pointer
8.4.4.Compare address