I had recently learned the basics of C++, and I somehow managed to grasp their syntax, but why would you ever need to use pointers? They only store a data address, but what is the point of even storing one in the first place?
Codecademy has a nice cheat sheet on references and pointers if you need a refresher, but I wish they provided some more real-world examples.
I program in Rust, not C/C++, so correct me if I’m wrong.
Unknown data
Lets say you want function that takes anything as input. You have no idea what the data is, so it’s hard to pass around. You also don’t know the size of the data in memory. Well, you can use a pointer, since the size of a pointer is always known. (C/C++ *void)
Writing to memory
Lets say you want to copy a string. How do you tell the copy function where to put the copied string in memory? Maybe you want to overwrite a string you already have.
Linked lists and similar
The whole point of linked lists is that each part is independent. If they are all in one value, they are forced to be put together. But, if you have each one store a pointer to the next one, then your problem is solved! Each part can be anywhere you want in memory.