The real difference is that the first is a reference to the member, you are simply saying that you should take the data from the member and the second is a dereference of the pointer contained in the member, saying that you should get the value pointed by the pointer on member. It is only syntactic sugar and the advantage is to write and read more easily. It is more obvious to see ->
and to know what is happening than to interpret (*ptr).membro
.
What does this do?
(*(*(*a).b).c).d
And this?
a->b->c->d
This is saying to get the value pointed out by d
that is member of c
that is member of b
which in turn is member of a
. The first one does the same thing but I will not even risk reading it aloud. Being explicit in intention is better.
In C ++ there is still the difference that the "arrow operator" can be overloaded.
C was meant to be an assembly portable and did not think much about the facilities for the programmer. If you think that normal in a program is working with final values and not with pointers, C is pretty annoying. By usability the normal would be to say that you want to catch the pointer by exception. But by C's philosophy this is not ideal. She has always sought to facilitate quick access and not usability. It was the 70s.
In fact there are discussions about how ->
is unnecessary in language. It really is possible not to use it but it had to be defined at the beginning of the language. It is possible for the compiler to know how access should only be done with .
but ->
was not syntax sugar .