An Arrow operator in C/C++ allows to access elements in Structures and Unions. It is used with a pointer variable pointing to a structure or union. The arrow operator is formed by using a minus sign, followed by the geater than symbol as shown below.
Syntax:
(pointer_name)->(variable_name)
Operation: The -> operator in C or C++ gives the value held by variable_name to structure or union variable pointer_name.
Difference between Dot(.) and Arrow(->) operator:
- The Dot(.) operator is used to normally access members of a structure or union.
- The Arrow(->) operator exists to access the members of the structure or the unions using pointers.
Examples:
- Arrow operator in structure:
// C program to show Arrow operator// used in structure#include <stdio.h>#include <stdlib.h>// Creating the structurestructstudent {charname[80];intage;floatpercentage;};// Creating the structure objectstructstudent* emp = NULL;// Driver codeintmain(){// Assigning memory to struct variable empemp = (structstudent*)malloc(sizeof(structstudent));// Assigning value to age variable// of emp using arrow operatoremp->age = 18;// Printing the assigned value to the variableprintf("%d", emp->age);return0;}chevron_rightfilter_noneOutput:18
- Arrow operator in unions:
// C program to show Arrow operator// used in structure#include <stdio.h>#include <stdlib.h>// Creating the unionunionstudent {charname[80];intage;floatpercentage;};// Creating the union objectunionstudent* emp = NULL;// Driver codeintmain(){// Assigning memory to struct variable empemp = (unionstudent*)malloc(sizeof(unionstudent));// Assigning value to age variable// of emp using arrow operatoremp->age = 18;// DIsplaying the assigned value to the variableprintf("%d", emp->age);}chevron_rightfilter_noneOutput:18
Recommended Posts:
- Logical Not ! operator in C with Examples
- Modulo Operator (%) in C/C++ with Examples
- Operands for sizeof operator
- Result of sizeof operator
- Result of comma operator as l-value in C and C++
- C/C++ Ternary Operator - Some Interesting Observations
- A comma operator question
- To find sum of two numbers without using any operator
- When should we write our own assignment operator in C++?
- Default Assignment Operator and References
- Set a variable without using Arithmetic, Relational or Conditional Operator
- sizeof operator in C
- C++ | Operator Overloading | Question 10
- C++ | Operator Overloading | Question 2
- C++ | Operator Overloading | Question 3
- C++ | Operator Overloading | Question 4
- C++ | Operator Overloading | Question 5
- C++ | Operator Overloading | Question 6
- C++ | Operator Overloading | Question 7
- C++ | Operator Overloading | Question 10
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

