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.
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?
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?
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.
@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?"