Skip to main content

Pointers – Understanding Memory Addresses

Updated 4 min readMarkdown
Part of seriesC Programming

If arrays taught you that data is stored next to each other in memory,
pointers will teach you how to access memory directly.

This is where C becomes powerful and a little scary.

But don’t worry. We’ll go step by step.

By the end of this lesson, you will understand:

  • What a pointer is

  • What & means

  • What * means

  • How dereferencing works

  • Why changing *p changes the original variable

1. What Is Memory?

When you write:

int n = 98;

The computer:

  • Finds a location in memory

  • Stores the value 98 there

  • Gives that location an address

Every variable has:

  • A value

  • An address

You normally work with the value.

Pointers let you work with the address.

2. Getting the Address of a Variable

To get the address of a variable, use the & operator.

Example:

#include <stdio.h>

int main() {
    int n = 98;
    printf("Value of n: %d\n", n);
    printf("Address of n: %p\n", &n);
    return 0;
}

&n means:

“Give me the address of n.”

%p is used to print memory addresses.

You will see something like:

0x7ffd3c4b8a1c

That is the memory location.

3. What Is a Pointer?

A pointer is:

A variable that stores the address of another variable.

It does not store the value directly.

It stores where the value lives.


4. Declaring a Pointer

To declare a pointer:

data_type *pointer_name;

Example:

int *p;

This means:

  • p is a pointer

  • It will store the address of an integer

Important:

The type matters.

If you write:

int *p;

Then p must point to an int.

5. Storing an Address in a Pointer

Example:

int n = 98;
int *p = &n;

What happens here?

  • n stores 98.

  • &n gives the address of n.

  • p stores that address.

So now:

p → address of n

6. Dereferencing a Pointer

The * operator has two meanings:

In declaration:

int *p;

It means “p is a pointer”.

In usage:

*p

It means:

“Go to the address stored in p and get the value.”

Example:

#include <stdio.h>

int main() {
    int n = 98;
    int *p = &n;

    printf("Value of n: %d\n", n);
    printf("Value using pointer: %d\n", *p);

    return 0;
}

*p gives you 98.

Because:

  • p stores the address of n

  • *p goes to that address

  • It retrieves the value stored there

7. Modifying a Value Using a Pointer

Here’s where it gets powerful.

#include <stdio.h>

int main() {
    int n = 98;
    int *p = &n;

    *p = 402;

    printf("n = %d\n", n);
    return 0;
}

What happens?

  • p points to n

  • *p = 402 changes the value at that address

  • Since that address belongs to n, n becomes 402

So pointers allow you to modify the original variable.

8. Visual Memory Example

Imagine memory like this:

Address: 1000
Value:   98

Now:

n → 1000
p → 1000

When you write:

*p = 402;

You are changing:

Value at address 1000

So n changes.

9. Why Pointers Matter

Pointers are used for:

  • Working with arrays

  • Strings

  • Dynamic memory

  • Passing variables to functions by reference

  • Building data structures

Without pointers, C would not be powerful.

10. Common Beginner Mistakes

❌ Using a pointer without initializing it

int *p;
*p = 10;   // Dangerous!

This causes undefined behavior.

Always assign an address before dereferencing.

❌ Confusing & and *

  • & → Get address

  • * → Go to address

❌ Forgetting pointer type must match variable type

float f = 3.14;
int *p = &f;  // Wrong

Types must match.

11. Practice Exercises

  1. Create an integer variable and print its address.

  2. Create a pointer that stores the address of that variable.

  3. Use the pointer to change the variable’s value.

  4. Draw the memory state on paper.

Try this:

int n;
int *p;
n = 98;
p = &n;
*p = 402;

Question:

  • What is the final value of n?

  • Why?

Final Thoughts

Today you learned:

  • Every variable has an address.

  • & gives the address.

  • A pointer stores that address.

  • *p accesses the value at that address.

  • Changing *p changes the original variable.

Pointers are not magic.

They are simply variables that store memory addresses.

In the next lesson, we will connect pointers and arrays.

And that’s when things really start making sense.

About the author

  • Heya! 👋 I love helping people, and one of the best ways I do this is by sharing what I learn and build. I started as a pharmacist at a tertiary hospital in Northern Ghana, where I saw how much technology could improve healthcare. That sparked my interest in digital health. I taught myself to code, then joined the ALX Software Engineering program, which became a turning point. I went on to complete a Master of Health Informatics at the University of Toronto. Today I am a software and AI engineer and a health informatician, and I practise remotely as a Digital Health Pharmacist. I combine clinical experience with technical skills to build tools that solve real problems in health and beyond, and I write here about what I build and what I learn.

No comments yet. Be the first to comment.

C Programming

Part 20 of 40

From today, I will be starting lessons on C programming in my ALX Software Engineering class and I look forward to sharing with you everything I learn through this series.

Up nextArrays and Pointers – Understanding Their RelationshipIn the last lesson, we learned: What pointers are How & gives an address How * dereferences a pointer Now we connect that knowledge to arrays. This is the moment many students say: “Ohhhh… so th

More from this blog