Pointers – Understanding Memory Addresses
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
&meansWhat
*meansHow dereferencing works
Why changing
*pchanges 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:
pis a pointerIt 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?
nstores 98.&ngives the address ofn.pstores 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:
pstores the address ofn*pgoes to that addressIt 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?
ppoints ton*p = 402changes the value at that addressSince that address belongs to
n,nbecomes 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
Create an integer variable and print its address.
Create a pointer that stores the address of that variable.
Use the pointer to change the variable’s value.
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.
*paccesses the value at that address.Changing
*pchanges 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.