简体   繁体   中英

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

Consider array 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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM