English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
.(dot) operator and ->(arrow) operator is used to refer to the members of classes, structures, and unions.
The dot operator is applied to the actual object. The arrow operator is used with a pointer to the object. For example, consider the following structure:
struct Employee { char first_name[16]; int age; }; emp;
The following code assigns the value "zara" to the object emp. first_name Members:
strcpy(emp.first_name, "zara");
If p_emp is a pointer pointing to an object of type Employee, then you need to assign the value "zara" to the first_name member of the object emp. first_name member, you need to write the following code:
strcpy(p_emp->first_name, "zara");
-> Known as the arrow operator, it is composed of a minus sign followed by a greater-than sign.
In short, use the dot operator to access the members of a structure, and use the arrow operator to access the members of a structure through a pointer.