Arrow Operator : Accessing Structure members using Pointer



Arrow (->) Operator : Accessing Structure members using Pointer

In C Programming we use arrow operator to access structure member using the pointer variable.

Syntax and Use of Arrow Operator :

struct student
{
  char name[20],
  int roll;
}*ptr;

Expalanation :

Whenever we declare structure variable then member can be accessed using the dot operator. But when pointer to a structure is used then arrow operator is used.

struct student
{
  char name[20],
  int roll;
}std;
struct student
{
  char name[20],
  int roll;
}*ptr;
Access Structure MemberExample 1Example 2
Name is accessed usingstd.nameptr->name
Roll number is accessed usingstd.rollptr->roll
Live Example : Click Here for Live Example