Monday, January 4, 2010

9.2 PROCESSING A STRUCTURE

Usually the members of  structure are processed individually, as separate entities.A structure member can be accessed by writing

variable.member;

where variable refers to the name of a structure-type variable, and member refers to the name of the member within the structure.Notice the period (.) that separates the variable name from the member name.This period is an operator;it is a member of highest precedence group, and its associativity is left to right.

Let us consider the following structure declarations.

struct date  {
int month;
int day;
int year;
};

struct account  {
int acct_no;
char acct_type;
char name[80];
float balance;
struct date lastpayment;

} customer;


Here customer is a structure variable of type account.If we are to access customer's account number, we would write

customer.acct_no

Similarly, the customer's name and the customer's balance can be accessed by writing

customer.name
and
customer.balance

No comments:

Post a Comment