If I have a struct like
struct account {
int account_number;
};
Then what’s the difference between doing
myAccount.account_number;
and
myAccount->account_number;
or isn’t there a difference?
If there’s no difference, why wouldn’t you just use the . notation rather than ->? -> seems so messy.
-> is a shorthand for
(*x).field, wherexis a pointer to a variable of typestruct account, andfieldis a field in the struct, such asaccount_number.If you have a pointer to a struct, then saying
is much more concise than