VOOZH about

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

⇱ dot (.) operator in C++ - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

dot (.) operator in C++

Last Updated : 11 Feb, 2026

dot (.) operator in C++ is used to access members (data and functions) of a class, struct, or union through an object. It allows direct interaction with an object’s components.

  • The dot (.) operator accesses member variables and functions using objects (not pointers) and is used for direct member access.
  • It has very high precedence in C++, just below brackets, and shares the same level with the arrow (->) operator.
  • The arrow (->) operator works similarly but accesses members through pointers instead of objects.
  • The dot (.) operator cannot be overloaded, and attempting to do so causes compile-time errors.

Output
Roll number is: 10

Syntax

variable_name.member;

  • variable_name: It's an instance of a class, structure, or union.
  • member: member variables or member functions associated with the created object, structure, or union.

Output
Accessing data members:
BMW
2024
Accessing member function:
Model: BMW
Year: 2024
Comment
Article Tags:
Article Tags: