C++ Learning Resource Network!

 
 
 
 
 C++ Tutorials  >  Data Types & Structures  >  The -> Operator
 

The -> Operator

The -> operator is used when a structure element has to be accessed through a pointer. The pointer should be initialized before it can access any structure element. Consider the following code fragment, which is used to initialize pointers for the user-defined data type invoice created earlier:

invoice *Invptr;
Invptr = new invoice;
Invptr->iInvoice_no = 1;
Invptr->fInvoice_amt = 100.00;


Another way of initializing pointers is:

invoice Inv1, *Invptr;
Invptr = &Inv1;
Invptr->iInvoice_no = 1;
Invptr->fInvoice_amt = 100.00;

 
 

| Bookmark This Site |   | Links |   | Search |   | Submit |   | Contact |

  Copyright 2008 - 3008  CppTutor.com All rights reserved.