what does  the '->' in 'pid->iState' mean?

Hi~ I've seen this operator (?) in a fair amount of C code I have looked at but can't figure out what it means:


(context below)

pid->iState += error;
if (pid->iState > pid->iMax) 
pid->iState =
else if (pid->iState

Hi roy,

pid is pointer to a structure and pid->iState is a reference to a member of that structure called iState.

Elsewhere in the code will be the definition of the structure that pid points to, there are lots of ways to do this but could be something like:

struct { int iState; int iMax; // other elements.... } id, *pid; // id is the structure, pid is a pointer to the structure

When the code accesses the structure directly, it can do something like this: id.iState = 1;

when it has the pointer to the structure, it does this: pid->iState = 1;

both change the value of iState in the id structure to 1

thanks! that helps a lot.

Also, it may help to think of -> as 'pointing to'

When I see the expression pid->iState = 1;

I hear it inside my head as: Set pid pointing to iState to one.

Yeah - I get that: seems like dot access of an instance property (obj.state = 1) I haven't used strucs but it seems like they a sort of static associative array

structures are collections of variables. They can include any mix of variable types (including arrays). They are a remarkably powerful and useful construct, learning to use structures is well worth the effort if you want to keep data organized in more complex programs.