O'Reilly logo

C Programming: Visual Quickstart Guide by Marc Liyanage, Larry Ullman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required