Previous | Home | Next |
Accessing structure member
To access structure members we can use dot operator (.) between structure name and structure member name as follows:
structure_name.structure_member
For example to access street name of structure address we do as follows:
1. struct address billing_addr; 2. billing_addr.country = "US";
If the structure contains another structure, we can use dot operator to access nested structure and use dot operator again to access variables of nested structure.
1. struct customer jack; 2. jack.billing_addr.country = "US";
Initializing structure
C programming langauge treats a structure as a custom data type therefore you can initialize a structure like a variable.
struct product{ char name[50]; double price; } book = { "C programming language",40.5};