224k views
3 votes
It is very common to store struct pointers rather than struct themselves, so common in fact that C provides an operator specifically for them. Which one of the following accesses a struct member directly from it's pointer?

a) .
b) []
c) *
d) ->
e) None of the above

1 Answer

4 votes

Final answer:

The correct answer is d) ->. When working with struct pointers in C, we use the arrow operator (->) to access members of the struct directly from the pointer.

Step-by-step explanation:

The correct answer is d) ->.

When working with struct pointers in C, we use the arrow operator (->) to access members of the struct directly from the pointer. This is because the pointer itself does not contain the actual members of the struct, but rather the memory address where the struct is stored. By using the arrow operator, we can access the struct members as if we were working with the struct itself.

For example, if we have a struct pointer called personPtr and it points to a struct called person with a member name, we can access the name using personPtr->name.

User Philouuuu
by
8.3k points