->

What does (->) does? Please with code example

As we use . operator with class or structure or any other user defined data type.

-> operator is used with pointer of those data types

eg
1
2
3
4
5
6
7
8
9
struct str{
   int a;
};

//in main
str aa;
aa.a=5;
str *p=&aa;
p->a=5;
Last edited on
Following Akshit's example, it basically means:

1
2
(*p).a = 5;
p->a = 5; // less to write and clearer 

What does (->) does? Please with code example

Oh, come on! You could look this up in seconds in any textbook!
Accessing member of object via pointer to that object is one place, but C++11 has also suffix return type syntax, where -> is used.
Topic archived. No new replies allowed.