The Address-of Operator

Finding out a variable's address is very simple: C provides the address-of operator (&) to do just that. This operator takes the name of a variable and returns the variable's starting address in memory. For now, think of an address as a big number.

If you have a variable defined as int counter, the correct syntax to get its address is &counter.

Our first example uses the address-of operator to show how variables are laid out in the memory of your computer. The five variables shown in Figure 9.1 will be used in the example so you can see for yourself how your particular environment stores the data.

To find a variable's address

1.
Create a new file or project in your text editor or IDE.
2.
Type the standard beginning lines ...

Get C Programming: Visual Quickstart Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.