Course contentsShow
← C
Lesson 451 of 1,2197. PointersFree lesson

Hexadecimal notation for memory

Hexadecimal notation for memory

What you'll learn: How to read and represent computer memory addresses using the base-16 numbering system.

The problem with big numbers

Imagine every byte of RAM in your computer has a unique house number (an address). In a modern machine with 8GB of RAM, there are billions of these addresses. If we wrote them in standard decimal (base-10), we’d be dealing with massive, clunky numbers like 4,294,967,295.

Binary (base-2) is even worse; it’s a sea of ones and zeros that no human can read at a glance. To solve this, C programmers use Hexadecimal (base-16). Hex is the "Goldilocks" of notation: it is compact like decimal but maps perfectly to the way computers handle bits.

How Hexadecimal works

In decimal, we count 0 through 9. In Hex, we need sixteen distinct symbols, so we use letters for the extra values:

  • 0–9: Same as decimal.
  • A–F: Represent 10 through 15.

In C, we prefix hexadecimal numbers with 0x to tell the compiler, "Hey, don't read this as a decimal!" For example, 0x10 isn't ten; it's sixteen.

Seeing addresses in action

When you ask C to show you where a variable lives in memory, it will almost always provide a hex code. Because memory is organized in chunks of 8 bits (1 byte), and two hex digits perfectly represent exactly 8 bits, it makes debugging much cleaner.

Here is how you print a memory address in C using the %p (pointer) format specifier:

#include <stdio.h>

int main() {
    int temperature = 72;
    
    // The & symbol gets the memory address of the variable
    // %p prints that address in hexadecimal format
    printf("The value is: %d\n", temperature);
    printf("The memory address is: %p\n", (void*)&temperature);
    
    return 0;
}

When you run this, you’ll see an output like 0x7ff7bfeff4a8. While it looks like gibberish at first, notice the 0x prefix and the mix of numbers and letters (a–f). This is a direct map to a specific physical location on your RAM sticks.

Key takeaway

Hexadecimal (0x) is a shorthand that makes long binary memory addresses readable for humans while staying mathematically aligned with how hardware functions.