just a quick (noob) question

closed account (30X1hbRD)
Hi, I've been taking C++ for a long while now and I was wondering what exactly could I use pointers for that I couldn't use a simple variable for? I'm still a bit of a noob at c++ is why I ask.
Sometimes variables need to exist across multiple functions/objects. A good example is managing resources. You load an image into memory, but you don't necessarily want to load that image into memory every time you need it. So you load it into memory once, and pass a pointer to that image around to objects that need to use it.
closed account (EwCjE3v7)
Take a look at this:
http://www.cplusplus.com/doc/tutorial/pointers/
closed account (30X1hbRD)
Thank you very much for the advice. I've seen tons of examples about how to use pointers but this is more helpful. Correct me if I'm wrong but in this case pointers are mostly used for saving memory then?
closed account (EwCjE3v7)
Well int,double and other variables store data to.

Example:
 
int test = 100


In this case the test which is an int is holding the value of 100
closed account (30X1hbRD)
CaptainBlastXD, I mean like if you had a really big project and needed to save memory you would have your base variables and use pointers as a form of saving memory?
the prince wrote:
use pointers as a form of saving memory?
Conserving memory is a better word. But you're right. In a larger project where you might have large objects, you would use pointers to avoid creating duplicates of those objects.
closed account (30X1hbRD)
Thanks a lot everyone! I'm very grateful for all the advice. I think I have a basic understanding now. Thank you all and good luck to all of you!
closed account (EwCjE3v7)
@the prince "CaptainBlastXD, I mean like if you had a really big project and needed to save memory you would have your base variables and use pointers as a form of saving memory?"

Yep. :)
Topic archived. No new replies allowed.