Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAnthony Albertorio
22,624 PointsA good resource to visualize pointers (pass by value vs pass by reference)
Great video.
Here are two things to help you (future viewer) on how to understand pointers, and when to use them.
Here is a picture describing "pass by value" vs "pass by reference"
Passing by value is passing a copy of the data. We don't mutate aka change the original data's state.
Passing by reference is passing the address in memory where the original value resides. Then we can mutate aka change the original value's state.
Although the article is about Java, the concepts of passing by value and reference are the same. The GIF will clear things up IMMENSELY https://blog.penjee.com/passing-by-value-vs-by-reference-java-graphical/
To simplify what a pointer is, think of this analogy. Think of memory as PO Box. (For those not of the USA, think about it as a room where lots of mail is stored. The room has a wall. This wall is full of little locked doors. Each door has a number. The room holds your mail for you and gives you key to open the door).
The mail inside of it is the data.
The & sign gets your the PO Box number. The * sign gets the mail inside that PO Box number.
If you pass by reference, you change the contents of the mail inside of the PO Box. If you pass by value, you change the content of a COPY of the mail. Imagine if the mail people can take a copy of your mail and send it to you via email. You would be changing the email copy, not the original.
Hope this helps!