Skip to main content

Command Palette

Search for a command to run...

Pointers – Understanding Memory Addresses

Published
4 min read
D

Heya! 👋 I love helping people, and one of the best ways I do this is by sharing my knowledge and experiences. My journey reflects the power of growth and transformation, and I’m here to document and share it with you.

I started as a pharmacist, practicing at a tertiary hospital in the Northern Region of Ghana. There, I saw firsthand the challenges in healthcare delivery and became fascinated by how technology could offer solutions. This sparked my interest in digital health, a field I believe holds the key to revolutionizing healthcare.

Determined to contribute, I taught myself programming, mastering tools like HTML, CSS, JavaScript, React, PHP, and more. But I craved deeper knowledge and practical experience. That’s when I joined the ALX Software Engineering program, which became a turning point. Spending over 70 hours a week learning, coding, and collaborating, I transitioned fully into tech.

Today, I am a Software Engineer and Digital Health Solutions Architect, building and contributing to innovative digital health solutions. I combine my healthcare expertise with technical skills to create impactful tools that solve real-world problems in health delivery.

Imposter syndrome has been part of my journey, but I’ve learned to embrace it as a sign of growth. Livestreaming my learning process, receiving feedback, and building in public have been crucial in overcoming self-doubt. Each experience has strengthened my belief in showing up, staying consistent, and growing through challenges.

Through this platform, I document my lessons, challenges, and successes to inspire and guide others—whether you’re transitioning careers, exploring digital health, or diving into software development.

I believe in accountability and the value of shared growth. Your feedback keeps me grounded and motivated to continue this journey. Let’s connect, learn, and grow together! 🚀

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.

C Programming

Part 21 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 next

Arrays – Storing Data in Blocks of Memory

So far, we’ve been working with single variables: int age = 20; int score = 85; That works fine when you only need one value. But what if you need to store: 5 test scores? 10 student IDs? 100 numb

More from this blog

D

Dr. Ehoneah Obed

75 posts

Software engineer writing about systems: in code, in learning, in life. I reverse-engineer complex problems into frameworks. Pharmacist → SWE → Founder.