In C ++ and - the difference> operator

Unlike  -> Operator

. (Dot) and operator -> (arrow) operator is used to reference a member of the class, and the common structural body: dot operator is applied to the actual object. The arrow operator used in conjunction with a pointer to the object.

For example, assume the following structure:

struct Employee { char first_name[16]; int age; } emp;

Point operator

The following code the value of first_name zara assigned to an object emp members:

strcpy(emp.first_name, "zara");

-> the arrow operator

If p_emp is a pointer to an object of type Employee, the value should be assigned to objects emp zara first_name member, they are necessary to write the following code:

strcpy(p_emp->first_name, "zara");

-> the arrow operator is called, it is a greater-than a minus sign.

Briefly, the dot operator to access members of the structure, while the structure of the pointer accesses by members, use the arrow operator.

In other words, with the structure defines an entity, then the entity to which the members of his references, use  the operator, if the structure is defined by a structure pointer, then the reference to members of his inside to use.  -> .

Guess you like

Origin www.cnblogs.com/gkh-whu/p/11487716.html