An Explanation of Pointers (C++)

Filed under
HowTos

Pointers are basically the same as any other variable. However, what is different about them is that instead of containing actual data, they contain a pointer to the memory location where information can be found. This is a very important concept, and many programs and ideas rely on pointers as the basis of their design, linked lists for example.

Getting Started

How do I define a pointer? Well, the same as any other variable, except you add an asterisk before its name.

So, for example, the following code creates two pointers, both of which point to an integer:

int* pNumberOne;
int* pNumberTwo;

Notice the 'p' prefix in front of the two variable names?

Full Story.