Machine-translated by Google. Questions are authored in English.
Top

Discussion

If a variable is a pointer to a structure, then which of the following operator is used to access data members of the structure through the pointer variable?

  • A..
  • B.&
  • C.*
  • D.->

Answer: D

Correct answer: ->

The arrow operator accesses a member through a pointer to a structure: p->member is by definition equivalent to (*p).member.

The parentheses in that expansion are essential, which is why the shorthand exists - . binds more tightly than *, so *p.member would be parsed as *(p.member) and rejected. The dot operator is for a structure object itself, not for a pointer to one.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.