C++ Learning Resource Network!

 C++ Tutorials  >  Data Types & Structures  >  The .(dot) Operator

The .(dot) Operator

Individual structure elements can be referenced by combining the .(dot) operator and the name of the structure variable. For example, the following statement assigns a value of 100.00 to the element flnvoice_amt of the structure variable Inv1 declared earlier.

Invl.flnvoice_amt = 100.00;

The structure variable name followed by the .(dot) operator and the element name will reference that structure element. The general form to access a structure element is: <structure variable>.<element name>

The following program illustrates input and output operations using structures:

//structure manipulation
struct bill
int iBill_no;
float fBill_amt;

void main()
char cReply;
cout<<"Enter Bill No.:";
cout<<"Enter Bill amount:";
cout<<"The amount for bill "<< Bill1.iBill_no<< " is: " << Bill1.fBill_amt<<endl;
cout<<"Enter y to continue";
}while(cReply == 'y');

The sample output of Program 8.1 is:
Enter Bill No. 1
Enter Bill amount 100.25
The amount for bill 1 si 100.25
Enter y to continue y
Enter Bill No. 2
Enter Bill amount 329.95
The amount for bill2 is 329.95
Enter y to continue n


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

  Copyright 2008 - 3008  CppTutor.com All rights reserved.