dot (.) operator in C++ (original) (raw)

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.

#include using namespace std;

class Student { public: int roll;

void show() {
    cout << "Roll number is: " << roll << endl;
}

};

int main() { Student s;
s.roll = 10;
s.show();

return 0;

}

`

**Syntax

variable_name.member;

#include using namespace std;

class Car { public: string model; int year;

Car(string m, int y) {
    model = m;
    year = y;
}

void showDetails() {
    cout << "Model: " << model << endl;
    cout << "Year: " << year << endl;
}

};

int main() {

Car c("BMW", 2024);

cout << "Accessing data members:" << endl;
cout << c.model << endl;
cout << c.year << endl;

cout << "Accessing member function:" << endl;
c.showDetails();

return 0;

}

`

Output

Accessing data members: BMW 2024 Accessing member function: Model: BMW Year: 2024