What does this operator " -> " means in c? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What does this operator " -> " means in c?

I want to know where is this operator is used and how it is used

5th Nov 2019, 5:53 PM
Rahul Nagpure
Rahul Nagpure - avatar
4 Answers
+ 3
#include <stdio.h> struct Number{ int x, y; }; int main() { struct Number n1 = {4,5}; struct Number* ptr = &n1; printf("%d",ptr->x + ptr->y); return 0; } The structure just contains two variables. In the main method an instance of it is created which is n1. Then we have created a pointer of structure type and assigned it to the address of n1. So now ptr is pointing to the structure n1 and by using -> this operator we can access the values of x and y of n1. And by the way you try to predict the output.
5th Nov 2019, 6:14 PM
Avinesh
Avinesh - avatar
+ 2
you should start challenging, i remeber exactly this question i had to answer frequently: p->a equals (*p).a where p is pointer and a is usually a member of class/sfructure
5th Nov 2019, 6:10 PM
Mateusz Kempa
Mateusz Kempa - avatar
+ 1
Thank You Very Much I have not yet completed c and c++ so i didnt knew that but i wanted to know that because i am studying for exam Thanks alot
5th Nov 2019, 6:20 PM
Rahul Nagpure
Rahul Nagpure - avatar
+ 1
Rahul Nagpure your welcome
5th Nov 2019, 6:21 PM
Avinesh
Avinesh - avatar