Which operator is used to access a member through a pointer to a C++ structure object?
Options
- A. .
- B. ->
- C. ::
- D. More than one of the above
- E. None of the above
Quiz Practice:
B. ->
Answer: (B) ->
When a pointer points to a structure object, the arrow operator (->) is normally used to access its members.
Example:
struct Student { int marks; };
Student s;
Student *p = &s;
p->marks = 90;
The expression p->marks accesses the marks member through the pointer.
The same operation can also be written using dereferencing and the dot operator as (*p).marks.