Latest web development tutorials

C ++ member operator

C ++ operator C ++ operator

. (Dot) operator and the -> (arrow) operator is used to reference the class members, and the union's structure.

Dot operator applied to the actual object. Arrow operator and a pointer to the object together. For example, suppose you have the following structure:

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

(.) Dot operator

The following code the value of "zara" assigned to an object emp offirst_name Members:

strcpy(emp.first_name, "zara");

(->) Arrow operator

If p_emp is a pointer to an object of type Employee, then take the value "zara" assigned to an object emp offirst_name members need to write the following code:

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

-> Called the arrow operator, which is a plus more than a minus number.

In short, use the dot operator to access members of the structure, while access by member pointer structure, use the arrow operator.

C ++ operator C ++ operator