This may sound like a dumb example, but if YOU want to move your arm, you have direct access to it, since it is attached to your body. The dot operator is used when there already is direct access (when you're using the structure variable itself, see MyStruct below).
If someone else wants to move your arm, they must (in effect) first establish a contact point with you to access it. The arrow operator is used when you first need to establish an access or contact point (when you're using a pointer to the structure variable, see pMyStruct below).
[ignore]
/* UserStruct is just the definition of a structure */
struct UserStruct
{
int iMemberID;
};
/* MyStruct is an actual instance of a structure */
/* you'll have to use the dot operator to access */
/* any of the structure's member variables */
UserStruct MyStruct;
MyStruct.iMemberID = 12345;
/* pMyStruct is not the structure, but a pointer to it */
/* you'll have to use the arrow operator to access any */
/* of the structure's member variables */
UserStruct* pMyStruct = MyStruct;
printf("%s\n", pMyStruct->iMemberID);
[/ignore]
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.