7. Pointers: Data by Location

C and C++ programmers are sometimes thought to be a special breed, in part because they understand pointers. This also gives C++ a reputation for being difficult. “What’s a pointer, anyway?” But the idea is fairly simple.

A pointer is just a variable that stores the location of another piece of data. Think of it this way: Sometimes it’s easier to write down a location to a cabinet full of data rather than to copy all the contents.

Which would you rather do: spend all night copying the contents of a file cabinet, or just tell someone (assuming it’s someone you trust) where the data is located? And consider what happens if you need to give this person the ability to change the data. Then you must give them the location ...

Get C++ Without Fear: A Beginner’s Guide That Makes You Feel Smart, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.