The Basics of Pointers in C

Matthew Clark
Nerd For Tech
Published in
2 min readMay 13, 2024

C Pointers are a type of variable used to store memory addresses of other variables. These pointers are typed meaning they will store the specified type and can be dereferenced. I will provide an example below.

In this example, we declare an integer (a) with a value of 5. This value is stored at memory address 0. Then we declare an integer pointer (a_ptr) with the memory address of (a). This value is stored at memory address 1. In C we use the asterisk (*) to declare a pointer and the ampersand (&) to get the memory address of a variable.

To dereference a pointer we use the asterisk (*) before the variable which will tell C to look up the value the variable points to.

Pointers are useful because they allow us to pass addresses to functions to directly manipulate the value we pass in.

In the example above we have a method that will add one to the given variable. With the use of pointers, we can directly manipulate a. This eliminates the need to add a return value because a will be changed directly.

In summary, a pointer is a variable that holds the memory address of another variable. They are declared and dereferenced using the asterisk (*) symbol. We can get the address of a variable using the ampersand (&) symbol. Pointers are useful when we want to pass the memory address of a variable around to operate on that variable directly.

--

--