Introduction to Structures in c
Introduction to Structures in c
struct Person {
char name[50];
int citNo;
float salary;
};
struct Person {
// code
};
int main() {
struct Person person1, person2;
return 0;
}
Another way of creating a struct
variable is:
struct Person {
// code
} person1, person2;
In both cases,
• person1 and person2 are struct Person
variables
Access Members of a Structure
There are two types of operators used for accessing member
a structure.
person2.salary
In this program, we have created a
struct named Person. We have also
created a variable of Person named
person1. In main(), we have assigned
values to the variables defined in
Person
for the person1 object.
strcpy(person1.name, "George
Orwell");
person1.citNo = 1984;
person1. salary = 2500;