Arrow operator (->)
Arrow operator is used for accessing members of structure using pointer variable, below is the syntax of arrow operator in c programming –Syntax 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.Both dot and arrow operator serves same function to access member of structure. Lets compare dot operator and arrow operator –
Example1:
Struct student
{
char name[20],
int roll;
}std;
Example2:
struct student
{
char name[20];
int roll;
}*ptr;
Access Structure Member | Example 1 | Example 2 |
---|---|---|
Name is accessed using | std.name | ptr->name |
Roll number is accessed using | std.roll | ptr->roll |
In case if we want to access the members of structure using ordinary structure variable then we can use dot operator.
No comments:
Post a Comment