user12184817
user12184817

Reputation:

Why do we use the dot operator (.) instead of the arrow operator (->) in arrays of structs as function parameters?

Considerarray is an array of variables of type structure (struct).

When you pass an array of structs as a parameter to a function, you access it with the dot (.) operator: array[0].structField1

Shouldn't it be accessed with the arrow (->) operator, since we're passing the address of the first element of the array, like: array[0]->structField1

Upvotes: 3

Views: 676

Answers (1)

dbush
dbush

Reputation: 225827

The array index operator [] contains an implicit pointer dereference. So if array has either array-of-struct or pointer-to-struct type, then array[0] has struct type and not pointer type.

Upvotes: 7

Related Questions