You can access the members of the structure using the dot operator (.). The general syntax is:
structureVariable.memberName
Here’s how you can assign values to the members of the person1 variable and then access them:
#include <stdio.h>
#include <string.h>
struct Person {
char name[50];
int age;
float height;
};
int main() {
struct Person person1;
// Assigning values to person1's members
strcpy(person1.name, "John Doe");
person1.age = 30;
person1.height = 5.9;
// Accessing and printing the values of person1's members
printf("Name: %s\n", person1.name);
printf("Age: %d\n", person1.age);
printf("Height: %.1f\n", person1.height);
return 0;
}
person1.name accesses the name member of person1, person1.age accesses the age member, person1.height accesses the height member.