Every variable lives somewhere in memory, and that place has an address. To get it, put the & sign in front of the variable name.

&rpm

This gives you the memory address of rpm.

Printing an address

To print an address, use the %p format specifier. It prints the address in hexadecimal.

#include <stdio.h>
 
int main() {
	char gear  = 'D';
	char mode  = 'S';
	char light = 'A';
	char fuel  = 'E';
 
	printf("Address of gear:  %p\n", (void *)&gear);
	printf("Address of mode:  %p\n", (void *)&mode);
	printf("Address of light: %p\n", (void *)&light);
	printf("Address of fuel:  %p\n", (void *)&fuel);
 
	return 0;
}
Address of gear:  0x7ffc3a1e5b4f
Address of mode:  0x7ffc3a1e5b4e
Address of light: 0x7ffc3a1e5b4d
Address of fuel:  0x7ffc3a1e5b4c

The addresses above are only an example. Yours will be different, and they can change from run to run.

Note

%p expects a void *, so the (void *) cast is the correct way to write it. Without the cast it usually works, but it is technically undefined behavior.

What the output tells us

Take the first line. The value 'D' is stored at the address printed for gear. The ASCII code for 'D' is 68, which is 0x44 in hex. So the single byte at that address holds 0x44.

A char takes 1 byte, so each of these variables occupies one byte of memory, and the address points to that byte.

Address size

Look at how long the address is. On a 64 bit machine, an address is 8 bytes, which is why you see up to 16 hex digits. On a 32 bit machine it would be 4 bytes.

In C, an address like this is also called a pointer, because it points to where the data is stored. We will use this idea a lot when we get to pointers.

Try it yourself

Compile and run the program on your own machine and see what addresses you get.

gcc main.c -o main
./main