Remember that steve is an integer and on most modern
computers an integer is a 4-byte data type, meaning that one
integer takes 4-bytes, or 32 bits, to be stored. When we say
that the address of steve is 728, what we mean is that
stevestarts at 728 and continues linearly through
the memory for as many bytes as needed. Had steve been a
character, which on most computers is a single byte data type,
steve would have been stored entirely in memory address
728.
Second, what is this "011011100" thing? It's binary
notation. When humans do arithmetic, we often use base 10,
meaning that each digit in a number represents some power of
10. For example, the decimal number 220 means 2*102 +2*101 +0*100 = 220. But there is no reason we have to use
base 10; we can use any base we like. For computers, base 2 is
the easiest. In Base 10, we can use digits 0 through 9; in
base 2 we can only use the digits 0 and 1. Why is this the
easiest base for computers? Because two numbers, 0 and 1, are
easily represented by the two states of a simple switch, on and
off. Inside your computer are hundreds of millions of these
tiny switches that can either be on or off, representing a 0 or
a 1. This corresponds nicely to base 2 notation. When you
store a number in a computer, the computer actually stores it
in base 2, even though you may have entered it in base 10. So,
when we store the decimal number 220 into the computer, it is
stored in base 2: 1*27 +1*26 +0*25 +1*24 +1*23 +1*22 +0*21 +0*20 = 220, hence the "011011100".
Another base commonly used by computer scientists is
hexadecimal notation. Hexadecimal is Base 16, meaning that
each digit represents 16 raised to a power (as opposed to 10
raised to a power in decimal notation, or 2 raised to a power
in binary notation). The digits in hexadecimal are represented
by the numbers 0 through 9, and then the letters A through F,
where A is 10, B is 11, etc, through F, which is 15. Why
hexadecimal? Because 16 is a power of 2 and corresponds nicely
to binary. Every hexadecimal digit (a hexit) is equivalent to
four binary digits. Because of this, it is easy to convert
from hex to binary and vice versa. This easy conversion makes
hexadecimal a convenient notation for representing binary
numbers in a more compact form. To let us know that a number
is hexadecimal, it is preceded by a "0x". For example, the
decimal number 220 is equivalent to the hexadecimal number
0xDC: D*161 + C*160 = 13*16 + 12 = 220.
Octal notation, base 8, is also a common base used by computer
scientists for a reason similar to that of hex: 8 is a power of
2. A single octal digit (an octit) is equivalent to three
binary digits. Octal notation places a 0 in front of every
number.
Base | Representation |
Base 10 (decimal) | 220 |
Base 2 (binary) | 0b011011100 |
Base 8 (octal) | 0334 |
Base 16 (hexadecimal) | 0xDC |
For more information on number representation and bits, please
refer to the SparkNote on the topic.
So what?
Back to the topic of pointers. Just as the purpose of the
steve variable is to store an integer, the purpose of a
pointer variable is to store a memory address, often the
address of another variable, such as steve. In the next
section, we'll see how to declare pointers and how to use them.
And after that, we'll see the answer to the question that is
probably forefront in your mind: "why?"