![]() |
VOOZH | about |
In C, the dot (.) operator is used to access members of user defined data types such as a structure or union. Also known as the direct member access operator, it allows us to access the data of the struct and union via the name of variables.
Let's take a look at an example:
30
Explanation: In the above code, a.x access the name and age members of the a structure. The dot operator is used to retrieve or modify values stored in these members of the structure.
Table of Content
name . member;
where,
The dot operator can also be used to access the members of nested structures and unions. It can be done in the same way as done for the normal structure.
name . member1 . member2;
The dot (.) operator has the highest operator precedence in C Language and its associativity is from left to right.
Note: dot (.) operator can only be used with structure or unions in C language.
The below examples demonstrate how to use the dot (.) operator in different cases:
10 Z
12