If p is a pointer to a struct record with a member named age, which expression reads that member?
Correct answer
D. p->age, which dereferences and selects
15 views
D. p->age, which dereferences and selects
15 views
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.
Asked in: NTS, PPSC IT, Campus Interviews
Not sure why the answer is D? Ask here and get an explanation.