The individual members of a structure variable are accessed using the dot operator (.). The structure variable is written first, followed by a dot and the required member name.
The individual members of a structure variable are accessed using the dot operator (.). The structure variable is written first, followed by a dot and the required member name.
Here, student is the structure variable and
rollNo and percentage are its members.
s1.rollNo accesses the rollNo member
of the structure variable s1.
A structure member can be used to read its stored value just like an ordinary variable.
The value stored in rollNo of s1
is displayed.
A structure member can also be assigned a new value using the dot operator.
The rollNo member of s1 is changed to
105.
Each member is accessed separately using the same structure variable followed by the dot operator.
Each statement accesses a different member of the same structure variable.
Write a C program to define a structure for a student, accept the student's roll number and percentage, and then display these values by accessing the structure members.
Create a structure named Student and use
s1.rollNo and s1.percentage to access
its members.
The dot operator is used with a structure variable to access its individual members. Each member can be read, assigned, or passed to a function separately.
Enter roll number: 101
Enter percentage: 82.5
Roll Number = 101
Percentage = 82.5
The dot operator is used when a normal structure variable is used
to access its members. Pointer-based structure access using
-> is a separate concept and is covered with pointers.
Students often forget to write the structure variable before the dot operator. The member name alone is not enough to identify which structure record should be accessed.
Incorrect: rollNo
Correct: s1.rollNo
| Concept | Remember |
|---|---|
| Dot Operator | Used to access members of a structure variable. |
| Syntax | structure_variable.member_name |
| Read Member | Use the member expression to obtain its value. |
| Update Member | Assign a new value using the member expression. |
Watch a beginner-friendly explanation of accessing structure members in C.
A short handwritten-style revision sheet for accessing structure members will be provided here.
Use the mind map for quick revision of structure variable, member and dot operator.