Saturday 13 July 2019

C++, when do I want to use a pointer to a variable instead of a variable itself?

I'm an (almost) 3rd year computer science student. I had a C++ programming module, but it did not go into details, just covered the basics. It introduced us to pointers, but I'm still wondering this:



Why (in what cases or circumstances) would one want to use a pointer to an int, as opposed to simply making an int itself? In other words, what are some good situations where using a pointer to a variable is better than simply declaring and initializing the variable itself? When are pointers to variables better than variables themselves?

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...