As the title states, what is the difference between -> and . I thought they were the same thing?
Asked
Active
Viewed 82 times
1 Answers
6
These are different operators, though related.
In C, .
is field selection, and ->
combines pointer dereference and field selection. So a->b
is equivalent to (*a).b
or more correctly (*(a)).b
.
Many languages don't have both .
and ->
. In C# and Java, for example, which don't have ->
, the .
operator does both dereference and field selection as in ->
in C. However, in C# and Java, .
also does selection from a namespace, which does not involve dereferencing (more like C++'s ::
operator).
Note: C# does have an unsafe
construct that allows for unsafe/raw pointers, and also does actually have the ->
operator to work with them. However, you won't encounter ->
unless you're working in unsafe
code.

Erik Eidt
- 33,747
->
is used in lambdas – yitzih Sep 28 '16 at 22:39->
remains a pointer dereference like C++ when you compile as unsafe. Lambdas are=>
. – Kevin Fee Sep 28 '16 at 22:43=>
for lambdas, that I forgot Java uses->
for that! – Erik Eidt Sep 29 '16 at 04:17