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 trialJake Nisenboim
3,374 PointsUnderstanding addresses and pointers [in C]
My understanding is that pointers are specific to saving memory?
They follow variables without having to hold the large amounts of data. I can later call the variable x by pointing to it rather than copying it.
How does that save memory?
Addresses are the places in memory in which the objects or variables are located.
Is this correct?
Thank you.
1 Answer
Martin Wildfeuer
Courses Plus Student 11,071 PointsMy understanding is that pointers are specific to saving memory?
Originally, yes. There's a bit more to it, though, have a look at Why C Pointers by Andrew Hardwick, that's a good read.
How does that save memory?
A pointer is a reference (the address) to data in memory. This data could be an instance of a person class, for example. This person object takes, let's say 50 kB of memory. By passing around this data via pointers, it will only ever take this 50 kB of memory. If it was copied, however, it would use another 50 kB of memory with every copy.
I hope this makes any sense, I always find myself in trouble when trying to find the right words for explaining pointers ;)
Steven Deutsch
21,046 PointsSteven Deutsch
21,046 PointsThanks for the resource Martin Wildfeuer
Martin Wildfeuer
Courses Plus Student 11,071 PointsMartin Wildfeuer
Courses Plus Student 11,071 PointsSteven Deutsch Sure thing! :)