Arrow operator -> in C/C++ with Examples Last Updated : 12 Jul, 2025 Comments Improve Suggest changes Like Article Like Report 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 greater 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 // C program to show Arrow operator // used in structure #include <stdio.h> #include <stdlib.h> // Creating the structure struct student { char name[80]; int age; float percentage; }; // Creating the structure object struct student* emp = NULL; // Driver code int main() { // Assigning memory to struct variable emp emp = (struct student*) malloc(sizeof(struct student)); // Assigning value to age variable // of emp using arrow operator emp->age = 18; // Printing the assigned value to the variable printf("%d", emp->age); return 0; } C++ // C++ program to show Arrow operator // used in structure #include <iostream> using namespace std; // Creating the structure struct student { char name[80]; int age; float percentage; }; // Creating the structure object struct student* emp = NULL; // Driver code int main() { // Assigning memory to struct variable emp emp = (struct student*) malloc(sizeof(struct student)); // Assigning value to age variable // of emp using arrow operator emp->age = 18; // Printing the assigned value to the variable cout <<" "<< emp->age; return 0; } // This code is contributed by shivanisinghss2110 JavaScript // JavaScript program to show Arrow operator used in structure let emp = null; // Creating the structure class Student { constructor(name, age, percentage) { this.name = name; this.age = age; this.percentage = percentage; } } // Assigning memory to struct variable emp emp = new Student('', 0, 0); // Assigning value to age variable // of emp using arrow operator emp.age = 18; // Printing the assigned value to the variable console.log(' ' + emp.age); Output: 18 Time complexity: O(1). Auxiliary space: O(n). // n is the size of memory that is being dynamically allocated using the malloc function to store the structure student. The amount of memory used is proportional to the size of the structure and the number Arrow operator in unions: C++ // C++ program to show Arrow operator // used in structure #include <iostream> using namespace std; // Creating the union union student { char name[80]; int age; float percentage; }; // Creating the union object union student* emp = NULL; // Driver code int main() { // Assigning memory to struct variable emp emp = (union student*) malloc(sizeof(union student)); // Assigning value to age variable // of emp using arrow operator emp->age = 18; // DIsplaying the assigned value to the variable cout <<""<< emp->age; } // This code is contributed by shivanisinghss2110 C // C program to show Arrow operator // used in structure #include <stdio.h> #include <stdlib.h> // Creating the union union student { char name[80]; int age; float percentage; }; // Creating the union object union student* emp = NULL; // Driver code int main() { // Assigning memory to struct variable emp emp = (union student*) malloc(sizeof(union student)); // Assigning value to age variable // of emp using arrow operator emp->age = 18; // DIsplaying the assigned value to the variable printf("%d", emp->age); } Output: 18 Comment More infoAdvertise with us Next Article Linked List in C A avsadityavardhan Follow Improve Article Tags : C Programs C Language Similar Reads Clockwise/Spiral Rule in C/C++ with Examples The Spiral/Clockwise Method is a magic tool for C/C++ programmers to define the meaning of syntax declaration in the head within seconds. This method was created by David Anderson and here is a short brief about how to apply this method. While coding, when someone comes across a new unwanted syntax 5 min read How to Create a Doubly Linked List in C? A doubly linked list is a type of linked list in which each node contains a pointer to both the next node and the previous node. This allows traversal in both forward and backward directions. Each node in a doubly linked list stores data, a pointer to the next node, and a pointer to the previous nod 4 min read Menu driven program for all operations on doubly linked list in C A Linked List is a linear data structure that consists of two parts: one is the data part and the other is the address part. A Doubly Linked List in contains three parts: one is the data part and the other two are the address of the next and previous node in the list. In this article, all the common 5 min read Linked List in C A linked list is a linear data structure where each element (called a node) is connected to the next one using pointers. Unlike array, elements of linked list are stored in random memory locations.In this article, we will learn about the linked list, its types, representation of the linked list in C 7 min read Linked List in C A linked list is a linear data structure where each element (called a node) is connected to the next one using pointers. Unlike array, elements of linked list are stored in random memory locations.In this article, we will learn about the linked list, its types, representation of the linked list in C 7 min read Increment and Decrement Operators in C The increment ( ++ ) and decrement ( -- ) operators in C are unary operators for incrementing and decrementing the numeric values by 1, respectively. They are one of the most frequently used operators in programming for looping, array traversal, pointer arithmetic, and many more.Increment Operator i 4 min read Like