top of page
Pointers
A pointer in C is a type of variable meant to denote the address of memory, or another variable. Pointers can be declared by using type *pointerName. For example to declare a pointer which points to integer x we can use int *y = &x;. We must make it equal to the address of (&) x not x itself.
Example:
Output:


By running the code multiple times we can see that the address of x changes every time. This is a security feature as it is harder to exploit something dynamic that changes every run.
An array is essentially a list of pointers which point at sets of data. We can use pointers to see the addresses of an array and notice that each part of the array is exactly the size of their type apart from each other.
Example:
Output:


Since our value is of type int, 4 bytes are taken up in memory per unit. The addresses are each 4 bytes apart from each other.
NULL Pointers
A NULL pointer is simply a pointer which is set equal to NULL. This may be useful to assign new pointers with no value at first equal to NULL so if they are read they do not accidentally point at some random number. The syntax for declaring a pointer equal to NULL is type *pointerName = NULL;
bottom of page