Quiz Entry - updated: 2026.07.06
What's the difference between . and -> in C++?
. accesses a member of an object; -> accesses a member through a pointer to an object.
Vehicle v(4);
v.show(); // object: use the dot
Vehicle *p = &v;
p->show(); // pointer: use the arrow
(*p).show(); // equivalent: dereference, then dot
Rule of thumb:
object.memberpointer->member
a->b is just shorthand for (*a).b. This is exactly the same rule C uses for structs — C++ simply extends it to classes (members include methods, not just fields).
Go deeper:
Pointer declaration — cppreference — pointers and reaching members through
->.