C accessing structure members

Accessing Structure Members

  1. Array elements are accessed using the Subscript variable , Similarly Structure members are accessed using dot [.] operator.
  2. (.) is called as “Structure member Operator”.
  3. Use this Operator in between “Structure name” & “member name”

Live Example :


struct Vehicle
    int wheels;
    char vname[20];
    char color[10];
}v1 = {4,"Nano","Red"};

int main()
printf("Vehicle No of Wheels : %d",v1.wheels);
printf("Vehicle Name           : %s",v1.vname);
printf("Vehicle Color          : %s",v1.color);

Output :

Vehicle No of Wheels : 4
Vehicle Name         : Nano
Vehicle Color        : Red

Note :

Dot operator has Highest Priority than unary,arithmetic,relational,logical Operators