βΉοΈ Skipped - page is already crawled
| Filter | Status | Condition | Details |
|---|---|---|---|
| HTTP status | PASS | download_http_code = 200 | HTTP 200 |
| Age cutoff | PASS | download_stamp > now() - 6 MONTH | 0.1 months ago |
| History drop | PASS | isNull(history_drop_reason) | No drop reason |
| Spam/ban | PASS | fh_dont_index != 1 AND ml_spam_score = 0 | ml_spam_score=0 |
| Canonical | PASS | meta_canonical IS NULL OR = '' OR = src_unparsed | Not set |
| Property | Value |
|---|---|
| URL | https://www.educative.io/answers/what-is-the-arrow-operator-in-c-cpp |
| Last Crawled | 2026-04-08 17:56:38 (1 day ago) |
| First Indexed | 2025-03-21 05:03:30 (1 year ago) |
| HTTP Status Code | 200 |
| Meta Title | What is the arrow operator (β>) in C/C++? |
| Meta Description | Contributor: M. Saddam Khalil |
| Meta Canonical | null |
| Boilerpipe Text | In the linked list example,
head
is a pointer to a
Node
type, and
head->data
and
head->next
are used to access members of the structure.
Conclusion
The arrow operator
->
is vital in managing objects and structures through pointers, especially in complex data structures. It ensures code readability by providing a clear and concise way to dereference pointers when accessing member elements, encapsulating the dereference operation
(*ptr).
into a straightforward
ptr->
expression.
Accelerate your coding journey β Master C and C++ today with our courses:
Learn C course
β Dive into C programming and master key concepts like data types, control flow, functions, pointers, and memory management. Plus, get hands-on with powerful debugging and optimization tools like GDB and gcc to refine your skills.
Learn C++ course
β Jumpstart your C++ journey with interactive execution sheets and flowcharts, perfect for beginners and those aspiring to become proficient C++ developers. |
| Markdown | .gif)

.gif)
You found the Easter Egg! 49% off your subscription for a few more hours.Easter Egg: Get 49% off\!
0d5h33m16s
Claim your offerClaim your offer
.gif)

Explore
EXPLORE THE CATALOGSupercharge your career with 700+ hands-on courses
View All Courses
Python
Java
JavaScript
C
React
Docker
Vue JS
R
Web Dev
DevOps
AWS
C\#
LEARNING TOOLSExplore the industry's most complete learning platform
CoursesLevel up your skills
Skill PathsAchieve learning goals
ProjectsBuild real-world applications
Mock InterviewsNewAI-Powered interviews
Personalized PathsGet the right resources for your goals
LEARN TO CODE
Check out our beginner friendly courses.
Pricing
For Business
Resources
[NewsletterCurated insights on AI, Cloud & System Design](https://www.educative.io/newsletter)
[BlogFor developers, By developers](https://www.educative.io/blog)
[Free CheatsheetsDownload handy guides for tech topics](https://www.educative.io/cheatsheets)
[AnswersTrusted answers to developer questions](https://www.educative.io/answers)
[GamesSharpen your skills with daily challenges](https://www.educative.io/games)
Search
Courses
Log In
Join for free
# What is the arrow operator (β\>) in C/C++?
## Arrow operator
The **arrow operator** `->` in C and C++ is used for accessing members (variables, methods) of a structure or class through a pointer. Itβs specifically applied in scenarios involving dynamic memory allocation, linked lists, and other data structures and instances where objects are accessed through their pointers.
## Arrow vs. dot operator
In the context of classes and structures in C and C++, when an object is accessed directly, its members are accessed using the dot operator (`.`). When an object is accessed through a pointer, the arrow operator `->` is used to access its members.
The syntax can be visually understood as follows:
- `object.member`: Using the dot operator to access a member directly
- `pointer->member` : Using the arrow operator to access a member through a pointer
Essentially, the following relation holds true:
Ace Editor
1
pointer\-\>member \== (\*pointer).member
ΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧ
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The expression `(*pointer).member` is a combination of dereferencing `*` and the dot operator `.`, which can be combined using the arrow operator `->`.
C++
C
Ace Editor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
\#include \<iostream\>
using namespace std;
class Point {
public:
int x;
int y;
};
int main() {
Point p1 \= {10, 20}; // Regular object of class Point
Point \*p2 \= &p1; // Pointer to p1
// Accessing members of p1 using the dot operator
cout \<\< "p1.x = " \<\< p1.x \<\< ", p1.y = " \<\< p1.y \<\< endl;
// Accessing members of the object pointed by p2 using the arrow operator
cout \<\< "p2-\>x = " \<\< p2\-\>x \<\< ", p2-\>y = " \<\< p2\-\>y \<\< endl;
return 0;
}
ΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧ
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Run
Dot (.) and arrow (-\>) usage
In the above example, `p1.x` and `p1.y` use the dot operator because `p1` is a regular variable of type `struct Point`. In contrast, `p2->x` and `p2->y` use the arrow operator because `p2` is a pointer to a `struct Point`.
### Usage with structures
#### Example 1: Basic usage
The provided C++/C code defines a structure `Sample` with an integer member `a`, creates an object `obj` of that structure, uses a [pointer](https://how.dev/answers/what-are-pointers-in-c) `ptr` to assign the value `5` to `obj.a` using the arrow operator, and outputs the assigned value to the standard output.
C++
C
Ace Editor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
\#include\<iostream\>
using namespace std;
struct Sample {
int a;
};
int main() {
Sample obj;
Sample\* ptr \= &obj;
ptr\-\>a \= 5; // Using arrow operator
cout\<\< "ptr-\>a: " \<\< ptr\-\>a \<\<endl;
return 0;
}
ΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧ
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Run
Basic usage of (-\>) operator
#### Example 2: Dynamic memory allocation
The provided C++/C code defines a [structure](https://how.dev/answers/how-to-use-structures-in-c) `Sample` with an integer member `a`, dynamically allocates memory for a `Sample` structure, assigns the value `5` to its `a` member using a pointer and the arrow operator, outputs the assigned value, and then frees the allocated memory, handling memory allocation failure with an error message.
C++
C
Ace Editor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
\#include\<iostream\>
using namespace std;
struct Sample {
int a;
};
int main() {
Sample\* ptr \= new Sample;
ptr\-\>a \= 5; // Using arrow operator
cout\<\< "ptr-\>a: " \<\< ptr\-\>a \<\<endl;
delete ptr; // Freeing allocated memory
return 0;
}
ΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧ
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Run
Dynamic memory allocation
### Usage with classes
#### Example 3: Accessing class members
The C++/C code snippet defines a class `Example` with an integer variable `x` and a member function `display()`, creates an object `obj` of `Example`, uses a pointer `ptr` to assign `10` to `x` and call `display()`, outputting the value of `x` using the arrow operator.
C++
C
Ace Editor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
\#include\<iostream\>
using namespace std;
// Define a class to hold data
class Example {
public:
int x;
void display() {
cout \<\< "Value of x: " \<\< x \<\< endl;
}
};
int main() {
Example obj;
Example\* ptr \= &obj;
ptr\-\>x \= 10; // Accessing variable using arrow operator
ptr\-\>display(); // Accessing function using arrow operator
return 0;
}
ΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧ
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Run
Show Solution
Accessing class members
#### Example 4: Linked list
In [linked list](https://www.educative.io/blog/linked-list-interview-questions) implementations, the arrow operator is used to traverse through the nodes by accessing the next nodeβs address.
C++
C
Ace Editor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
\#include\<iostream\>
using namespace std;
struct Node {
int data;
Node\* next;
};
// Function to print linked list data
void print(Node\* head) {
Node\* current \= head;
while(current != NULL) {
cout \<\< current\-\>data \<\< " ";
current \= current\-\>next;
}
cout \<\< endl;
}
int main() {
Node\* head \= new Node;
head\-\>data \= 1; // Assigning data to node using arrow operator
head\-\>next \= NULL; // Ensuring the list ends here
print(head); // Calling print to display linked list data
// Free the dynamically allocated memory
delete head;
ΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧΧ
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Run
Use in the linked list
In the linked list example, `head` is a pointer to a `Node` type, and `head->data` and `head->next` are used to access members of the structure.
### Conclusion
The arrow operator `->` is vital in managing objects and structures through pointers, especially in complex data structures. It ensures code readability by providing a clear and concise way to dereference pointers when accessing member elements, encapsulating the dereference operation `(*ptr).` into a straightforward `ptr->` expression.
Accelerate your coding journey β Master C and C++ today with our courses:
- [**Learn C course**](https://www.educative.io/courses/learn-c) β Dive into C programming and master key concepts like data types, control flow, functions, pointers, and memory management. Plus, get hands-on with powerful debugging and optimization tools like GDB and gcc to refine your skills.
- [**Learn C++ course**](https://www.educative.io/courses/learn-cpp) β Jumpstart your C++ journey with interactive execution sheets and flowcharts, perfect for beginners and those aspiring to become proficient C++ developers.
Relevant Answers
[What is nanf() in C/C++?](https://www.educative.io/answers/what-is-nanf-in-c-cpp)
[What is the difference between using void\* in C and C++?](https://www.educative.io/answers/what-is-the-difference-between-using-void-star-in-c-and-cpp)
[What is a diamond problem in Object-Oriented Programming?](https://www.educative.io/answers/what-is-a-diamond-problem-in-object-oriented-programming)
[What is nanf() in C/C++?](https://www.educative.io/answers/what-is-nanf-in-c-cpp)
[What is the difference between using void\* in C and C++?](https://www.educative.io/answers/what-is-the-difference-between-using-void-star-in-c-and-cpp)
[What is a diamond problem in Object-Oriented Programming?](https://www.educative.io/answers/what-is-a-diamond-problem-in-object-oriented-programming)
[Explore Answers](https://www.educative.io/answers)
Explore Courses
[Course Rediscovering JavaScript: ES6, ES7 & ES8 Gain insights into ES6, ES7, and ES8 modern JavaScript features. Delve into variables, classes, promises, and metaprogramming. Discover techniques for writing efficient and concise code. 13 h intermediate](https://www.educative.io/courses/rediscovering-javascript)
[Course The JavaScript Interview Handbook: 100+ Interview Questions The ultimate guide to JavaScript interviews. Developed by FAANG engineers, practice with real-world interview questions, gain confidence, and get interview-ready in just a few hours. 10 h intermediate](https://www.educative.io/courses/javascript-interview-handbook)
[Course Simplifying JavaScript: A Handy Guide for Software Engineers Gain insights into modern JavaScript, focusing on impactful syntax and practical usage. Discover essential language features and 51 valuable tips to enhance your productivity as a developer. 10 h beginner](https://www.educative.io/courses/simplifying-javascript-handy-guide)
[Course JavaScript In Practice: ES6 And Beyond Gain insights into ES6's enhancements in JavaScript. Delve into practical uses, discover easier coding with new features, and adopt modern practices through interactive exercises and quizzes. 10 h beginner](https://www.educative.io/courses/javascript-in-practice-es6-and-beyond)
[Course The All-in-One Guide to C++20 Gain insights into C++20's flagship features: concepts, modules, range library, and coroutines. Delve into standard library updates, concurrency, example code, and practical case studies. 13 h intermediate](https://www.educative.io/courses/all-in-one-guide-cpp-20)
[Course Step Up Your JS: A Comprehensive Guide to Intermediate JavaScript Gain insights into intermediate JavaScript, mastering interview questions, common design patterns, and deep understanding of the language. Learn with expert Arnav Aggarwal's engaging teaching method. 20 h beginner](https://www.educative.io/courses/step-up-your-js-a-comprehensive-guide-to-intermediate-javascript)
[Course PHP 8 Programming Tips, Tricks, and Best Practices Delve into PHP 8βs latest features, explore the JIT compiler, learn about asynchronous programming, and gain insights into efficient coding techniques to fast-track your PHP development skills. 40 h advanced](https://www.educative.io/courses/php-8-programming-tips-tricks-and-best-practices)
[Course React Deep Dive: From Beginner to Advanced Gain insights into React from basics to advanced, explore its ecosystem, and delve into best practices and the latest straightforward methods for efficient use. 16 h 40 min beginner](https://www.educative.io/courses/react-beginner-to-advanced)
[Course Game Development with JavaScript: Creating Tetris Gain insights into game development with JavaScript. Delve into graphics, game loops, and collision detection by creating Tetris. Showcase your skills with a fully functioning game. 5 h 30 min beginner](https://www.educative.io/courses/game-development-js-tetris)
[Course The Complete Guide to Modern JavaScript Gain insights into JavaScript from basics to ES2021, delve into TypeScript essentials, and test your knowledge through quizzes and coding challenges to reinforce learning. 6 h beginner](https://www.educative.io/courses/complete-guide-to-modern-javascript)
[Course Rediscovering JavaScript: ES6, ES7 & ES8 +3 intermediate 13hour](https://www.educative.io/courses/rediscovering-javascript)
[Course The JavaScript Interview Handbook: 100+ Interview Questions +3 intermediate 10hour](https://www.educative.io/courses/javascript-interview-handbook)
[Course Simplifying JavaScript: A Handy Guide for Software Engineers +3 beginner 10hour](https://www.educative.io/courses/simplifying-javascript-handy-guide)
[Course JavaScript In Practice: ES6 And Beyond +3 beginner 10hour](https://www.educative.io/courses/javascript-in-practice-es6-and-beyond)
[Course The All-in-One Guide to C++20 +3 intermediate 13hour](https://www.educative.io/courses/all-in-one-guide-cpp-20)
[Course Step Up Your JS: A Comprehensive Guide to Intermediate JavaScript +3 beginner 20hour](https://www.educative.io/courses/step-up-your-js-a-comprehensive-guide-to-intermediate-javascript)
[Course PHP 8 Programming Tips, Tricks, and Best Practices +3 advanced 40hour](https://www.educative.io/courses/php-8-programming-tips-tricks-and-best-practices)
[Course React Deep Dive: From Beginner to Advanced +3 beginner 16hour 40 min](https://www.educative.io/courses/react-beginner-to-advanced)
[Course Game Development with JavaScript: Creating Tetris +3 beginner 5hour 30 min](https://www.educative.io/courses/game-development-js-tetris)
[Course The Complete Guide to Modern JavaScript +3 beginner 6hour](https://www.educative.io/courses/complete-guide-to-modern-javascript)
[Explore Courses](https://www.educative.io/explore)
Free Resources
blog
[Julia vs. Python: A comprehensive comparison](https://www.educative.io/blog/julia-vs-python)
blog
[R Tutorial: a quick beginner's guide to using R](https://www.educative.io/blog/r-tutorial-beginners-guide)
blog
[Kubernetes: A Comprehensive Tutorial for Beginners](https://www.educative.io/blog/kubernetes-tutorial-for-beginners)
Copyright Β©2026 Educative, Inc. All rights reserved |
| Readable Markdown | In the linked list example, `head` is a pointer to a `Node` type, and `head->data` and `head->next` are used to access members of the structure.
### Conclusion
The arrow operator `->` is vital in managing objects and structures through pointers, especially in complex data structures. It ensures code readability by providing a clear and concise way to dereference pointers when accessing member elements, encapsulating the dereference operation `(*ptr).` into a straightforward `ptr->` expression.
Accelerate your coding journey β Master C and C++ today with our courses: [**Learn C course**](https://www.educative.io/courses/learn-c) β Dive into C programming and master key concepts like data types, control flow, functions, pointers, and memory management. Plus, get hands-on with powerful debugging and optimization tools like GDB and gcc to refine your skills. [**Learn C++ course**](https://www.educative.io/courses/learn-cpp) β Jumpstart your C++ journey with interactive execution sheets and flowcharts, perfect for beginners and those aspiring to become proficient C++ developers. |
| Shard | 28 (laksa) |
| Root Hash | 12990463358539855228 |
| Unparsed URL | io,educative!www,/answers/what-is-the-arrow-operator-in-c-cpp s443 |