VOOZH about

URL: https://www.geeksforgeeks.org/c/dot-operator-in-c/

⇱ dot (.) Operator in C - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

dot (.) Operator in C

Last Updated : 26 Dec, 2024

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:


Output
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.

Syntax of Dot Operator

name . member;

where,

  • name: An instance of a structure or a union.
  • member: member associated with the created structure or union.

dot(.) operator with Nested Types

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;

Precedence of dot (.) Operator

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.

Examples of dot (.) Operator

The below examples demonstrate how to use the dot (.) operator in different cases:

Accessing Members of Union


Output
10
Z

Access Nested Member Structure


Output
12
Comment
Article Tags:
Article Tags: