The Dot(.) and Arrow(->) Operators


In C, the dot (.) and the arrow(->) operators access individual elements of structures and unions. Structures and unions are national types of composite data that can be referred to as units. In C++, the dot and arrow operators are also used to access the members of a class.

The dot operator is used when working directly with any structure or union. The arrow operator is used when a structure or union pointer is used. For example,

Example of pointer operator

Program
struct employee
{
 char _name[100];
 int _age;
 float _wage;
} emp;

struct employee *a = &emp; /* address of emp into a */

You would write the following code to assign the 134.39 to the _wage member of structure variable emp:

emp._wage = 134.39;

However, the same assignment using a pointer to emp would be

a->_wage = 134.39;