->

Aug 15, 2013 at 11:42am
What does (->) does? Please with code example

Aug 15, 2013 at 11:49am
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 Aug 15, 2013 at 11:49am
Aug 15, 2013 at 12:16pm
Following Akshit's example, it basically means:

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

Aug 15, 2013 at 12:48pm
What does (->) does? Please with code example

Oh, come on! You could look this up in seconds in any textbook!
Aug 15, 2013 at 12:56pm
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.