Skip to content

Commit 855f1ff

Browse files
author
Ruby
committed
Explained asterisk on & and &mut reference
1 parent 8f3901f commit 855f1ff

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/doc/trpl/references-and-borrowing.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ This will print `6`. We make `y` a mutable reference to `x`, then add one to
125125
the thing `y` points at. You’ll notice that `x` had to be marked `mut` as well,
126126
if it wasn’t, we couldn’t take a mutable borrow to an immutable value.
127127

128+
You'll also notice we added an asterisk in front of `y`, making it `*y`,
129+
this is because y is an `&mut` reference. You'll also need to use them for
130+
accessing and modifying `&` references as well.
131+
128132
Otherwise, `&mut` references are just like references. There _is_ a large
129133
difference between the two, and how they interact, though. You can tell
130134
something is fishy in the above example, because we need that extra scope, with

0 commit comments

Comments
 (0)