C Programming Tutorial
Computer Tutorial

Accessing Structure Members



Accessing Structure Members

Individual members of a structure are accessed through the use of the . operator (usually called the dot operator). For example, the following statement assigns the ZIP code 12345 to the zip field of the structure variable addr_info declared earlier :
addr_info.zip = 12345;
The object name (in this case, addr_info) followed by a period and the member name (in this case, zip) refers to that individual member. The general form for accessing a member of a structure is
object-name.member-name ;

Therefore, to print the ZIP code on the screen, write :
printf("%lu", addr_info.zip);
This prints the ZIP code contained in the zip member of the structure variable addr_info.