Programming Concepts: Pointers
A pointer is a data type whose value refers directly to (or "points to") another value stored elsewhere in the computer memory using its address.

Pointers are incredibly important computing concepts as we need pointers to create many of the ADTs (Abstract Data Types) we are going to talk about. Some languages don't allow you to directly manipulate them, but all languages use them. For this section of the book you need to be familiar with the concept of pointers as we'll be using them heavily when we talk about linked lists, queues and stacks.
Quick examples of pointers might include the next free memory location in an array, or the location in memory that an array is stored at.
Example: Pointers Let's take a look at how pointers are used in the C programming Language. We are going to deal with two variables: a ptr We are also going to meet two key characters:
Assume that int a = 5;
int *ptr = NULL;
(The NULL pointer shown here is 0x00000000.)
By assigning the address of ptr = &a;
yields the following memory values:
Then by dereferencing *ptr = 8;
the computer will take the contents of
Clearly, accessing |
Exercise: Pointers Give a uses for pointers: Answer: storing next free memory addresses. Used to create abstract data types. What would the following output, where int q = 89;
int *next = NULL;
next = &q;
cout << *next;
q = 23;
*next = 56;
cout << q;
Answer:
56 |