Open In App
Related Articles

dot (.) Operator in C

Improve Article
Save Article
Like Article

The C dot (.) operator is used for direct member selection via the name of variables of type struct and union. Also known as the direct member access operator, it is a binary operator that helps us to extract the value of members of the structures and unions.

Syntax of Dot Operator

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

Example of dot(.) Operator


// C program to demonstrate the use of dot operator
#include <stdio.h>
struct str {
    int mem;
union un {
    int mem1;
    char mem2;
int main()
    struct str str_name = { 12};
    union un un_name;
    // accessing union member
    un_name.mem1 = 9;
    printf("Union Member 1: %d\n", un_name.mem1);
    // accessing structure member
    printf("Structure Member: %d", str_name.mem);
    return 0;


Union Member 1: 9
Structure Member: 12

dot(.) operator with Nested Structures and Unions

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.

Syntax with Nested Struct




// C program to illustrate the use of dot operator for
// nested structure
#include <stdio.h>
struct base {
    struct child {
        int i;
    } child;
int main()
    struct base s_name = { 12 };
      // accessing nested structure member using dot operator
    printf("Nested Structure Variable: %d", s_name.child.i);
    return 0;


Nested Structure Variable: 12

Operator Precedence of dot (.) Operator

The dot (.) operator has the highest operator precedence in C Language and its associativity is from left to right. To know more about operator precedence, please refer to the Operator Precedence in C.

Note: dot (.) operator can only be used with structure or unions in C language.

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 05 Mar, 2023
Like Article
Save Article
Similar Reads