1. Home
  2. Computer Science MCQs
  3. C Programming
  4. If p is a pointer to a struct record with a member named…

Added 30 Nov -0001

If p is a pointer to a struct record with a member named age, which expression reads that member?

  1. p.age, which selects from the pointer itself
  2. *p.age, which binds the dot first
  3. &p.age, which takes the member address
  4. p->age, which dereferences and selects Correct answer

Correct answer

D. p->age, which dereferences and selects

15 views

MCQSEXAM

Explanation

The arrow operator combines a dereference with member selection, so p->age is exactly equivalent to (*p).age. Writing p.age fails to compile because the dot expects a struct value, and *p.age is parsed as *(p.age) because the dot binds tighter than the star. The arrow is the conventional choice for linked-list and tree code where nodes are handled through pointers.

Reference

Asked in: NTS, PPSC IT, Campus Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is D? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More C Programming MCQs

Practise all C Programming MCQs

Similar MCQs