What are pointers?
We know that C has both ''standard'' variables,
holding integers, characters, and floating-point values,
termed scalar variables.
In addition, we've seen arrays and structures of these,
termed aggregate variables.
Let's follow this simplified explanation:
- We understand that variables occupy memory locations (1 or more
bytes) of a computer's memory.
- Each variable requires enough (at least) bytes to store the values the variable
will (ever) need to hold.
For example,
on typical desktop and laptop computers
a simple C integer will require 4 bytes of memory.
However a bool value, only requiring 1-bit, will typically occupy 1 byte.
- Similarly, an array of 100 integers,
will require 400 bytes of contiguous memory -
there is no padding between elements.
- Computers have a large amount of memory,
e.g. our lab computers have 16 gigabytes of memory (16GB),
or nearly 17.1 billion bytes.
- Each of a computer's memory bytes is uniquely numbered,
from 0 to some large value.
Each such number is termed the byte's memory address.
- We often refer to memory locations as just addresses
and the action of identifying an address as addressing.
|
|
With these points in mind, we can make 3 simple statements:
- Pointers are variables that hold the
address of a memory location.
- Pointers are variables that point to
memory locations.
- Pointers (usually) point to memory locations being
used to hold variables' values/contents.
CITS2002 Systems Programming, Lecture 11, p2, 26th August 2024.
|