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.
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.
Comments
Join the discussionNo comments yet. Be the first to comment.
C Programming
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.
