C++Tutorial for Beginners 37 - Pointers; Where C++ Starts to Get Tricky

Pointers are not as hard as you might think ... they just require a little practice. The point at which many people give up with C++ is when they get to pointers. Suddenly we're dealing not just with variables, but address of variables, via an array of asterisks and ampersands. For me, pointers seemed like a huge mental stretch when I first encountered them, but now it's hard to understand how I could have ever been perplexed by them. As always, the key to understanding is through typing and getting your own programs to work. After using pointers in a few demo programs, you start to develop a feel for which asterisk should be where. After that, the concept behind them doesn't seem so bewildering.

In fact, using a pointer is a lot like giving someone your address instead of taking your house round on your back for when you want to receive visitors. By specifying where, in the computer's memory, a chunk of data is located, we avoid having to physically copy that data from one chunk of memory to another (from one variable to another) in situations where we want to pass that data to a function.

Click here to download source code for this tutorial.