Pointer Variables and Pointers to Pointers
A pointer is a variable that stores an address. Learn how to declare and use pointer variables, how a pointer to a pointer works, and the jargon of pointers, with memory diagrams.
kvi5hnuCode Sprout team member6 min readOn this page
The previous article showed that &x gives the address of x, and that * gives the value stored at an address. It ended by storing an address in a second variable. This article looks closely at that variable: how it is declared, what its declaration really says, how one pointer can hold the address of another, and the vocabulary programmers use when they talk about pointers.
Declaring a Pointer
A variable that will hold the address of an int is declared like this:
int *ptr;
This tells the compiler that ptr will be used to store the address of an integer — in other words, ptr points to an int.
Why is there a * in the declaration? Read it using the meaning of * you already know: value at address. Then int *ptr says: the value at the address stored in ptr is an int.

So the declaration does not describe ptr directly. It describes what you get when you apply * to ptr — and that is an int.
Everything So Far in One Program
The program below combines &, * and a pointer variable. Before running it, try to predict each line using the memory map from the previous article: marks holds 88, and ptr holds the address of marks.
#include <stdio.h>
int main(void)
{
int marks = 88;
int *ptr;
ptr = &marks;
puts("-- addresses --");
printf("&marks : %p\n", (void *)&marks);
printf("ptr : %p\n", (void *)ptr);
printf("&ptr : %p\n", (void *)&ptr);
puts("-- values --");
printf("marks : %d\n", marks);
printf("*(&marks) : %d\n", *(&marks));
printf("*ptr : %d\n", *ptr);
return 0;
}
A sample run (the addresses will be different on your machine and on every run):
-- addresses --
&marks : 0x7ffe1509839c
ptr : 0x7ffe1509839c
&ptr : 0x7ffe150983a0
-- values --
marks : 88
*(&marks) : 88
*ptr : 88
What to notice:
&marksandptrare equal —ptrstores the address ofmarks.&ptris different —ptris a separate variable at its own location.marks,*(&marks)and*ptrare all88— three ways of reaching the same value: by name, through its address, and through a pointer that holds its address.
Pointers of Other Types
The same pattern works for any type. Here are three pointer declarations:
int *count_ptr;
char *letter_ptr;
double *price_ptr;
All three are pointer variables: each one can hold an address. An address is a location number in memory, so every pointer holds that kind of value, whatever type it is declared with.
The type in the declaration describes what is stored at that address, not what the pointer itself holds:
| Declaration | What the pointer holds | What *pointer gives |
|---|---|---|
int *count_ptr; | the address of an int | an int |
char *letter_ptr; | the address of a char | a char |
double *price_ptr; | the address of a double | a double |
A Pointer to a Pointer
A pointer is a variable, so it has an address too. That address can be stored in yet another variable — a pointer to a pointer:
int marks = 88;
int *ptr = &marks; /* pointer to an int */
int **pptr = &ptr; /* pointer to a pointer to an int */
Read int **pptr with the same rule as before: **pptr — the value at the address stored at the address in pptr — is an int.

Each * follows one arrow in the picture:
| Expression | Follows | Result (using the picture) |
|---|---|---|
pptr | – | 4200, the address of ptr |
*pptr | one arrow | 3000, the value stored in ptr |
**pptr | two arrows | 88, the value of marks |
#include <stdio.h>
int main(void)
{
int marks = 88;
int *ptr = &marks; /* pointer to an int */
int **pptr = &ptr; /* pointer to a pointer to an int */
puts("-- where each variable lives --");
printf("&marks : %p\n", (void *)&marks);
printf("&ptr : %p\n", (void *)&ptr);
printf("&pptr : %p\n", (void *)&pptr);
puts("-- what each variable stores --");
printf("ptr : %p (address of marks)\n", (void *)ptr);
printf("pptr : %p (address of ptr)\n", (void *)pptr);
printf("*pptr : %p (value stored in ptr)\n", (void *)*pptr);
puts("-- reaching marks --");
printf("marks : %d\n", marks);
printf("*ptr : %d\n", *ptr);
printf("**pptr : %d\n", **pptr);
return 0;
}
A sample run (the addresses will be different on your machine and on every run):
-- where each variable lives --
&marks : 0x7ffdf0fc9264
&ptr : 0x7ffdf0fc9268
&pptr : 0x7ffdf0fc9270
-- what each variable stores --
ptr : 0x7ffdf0fc9264 (address of marks)
pptr : 0x7ffdf0fc9268 (address of ptr)
*pptr : 0x7ffdf0fc9264 (value stored in ptr)
-- reaching marks --
marks : 88
*ptr : 88
**pptr : 88
Match each line to the memory map: pptr equals &ptr, *pptr equals ptr (which equals &marks), and **pptr reaches 88.
How Far Can This Go?
To compare the three declarations:
int marks; /* an ordinary int */
int *ptr; /* a pointer to an int */
int **pptr; /* a pointer to a pointer to an int */
Nothing stops you from adding more levels — int *** is a pointer to a pointer to a pointer, and so on. In practice, programs rarely need more than two levels; beyond that the code becomes hard for people to follow.
The Jargon of Pointers
Consider this fragment:
int temperature = 21;
int *tp;
tp = &temperature;
Which of these statements are true?
tpholds the address of anint.- The value at the address held in
tpis anint. tpis anintpointer.tppoints to anint.tpis a pointer that points in the direction of anint.
All of them. They are five ways of saying one fact: tp holds the address of an int, so it is called an int pointer. This is the vocabulary that makes pointers sound harder than they are — each phrase is just shorthand for "holds the address of".
The same naming rule applies to any type. A pointer is named after the kind of thing whose address it holds:
| A pointer holding the address of… | is called… |
|---|---|
an int | an int pointer |
a float | a float pointer |
| an array | an array pointer |
| a structure | a structure pointer |
| a function | a function pointer |
Key Takeaways
int *ptr;reads as "the value at the address stored inptris anint".- A pointer always holds an address; its declared type describes what lives at that address.
- A pointer has its own address, so
&ptris different fromptr. - A pointer to a pointer (
int **pptr) holds the address of another pointer; each*follows one level. - "Points to an
int", "intpointer" and "holds the address of anint" all mean the same thing.
Practice Questions
Given int *ptr = &marks;, which two expressions in the first program always print the same address?
&marks and ptr. ptr was assigned &marks, so its value is the address of marks. &ptr is the address of ptr itself and is different.
What does char *letter_ptr; say about letter_ptr? Does it hold a character?
No. letter_ptr holds an address. The declaration says that the value stored at that address is a char, so *letter_ptr is a char.
In the pointer-to-pointer picture, what are pptr, *pptr and **pptr?
pptr is 4200 (the address of ptr), *pptr is 3000 (the value stored in ptr, which is the address of marks), and **pptr is 88 (the value of marks).
If you declared int ***p3 = &pptr;, how many * would you need to reach marks?
Three: ***p3. *p3 is pptr, **p3 is ptr, and ***p3 is marks.
A pointer q holds the address of a structure. What would you call q?
A structure pointer. A pointer is named after the type of the thing whose address it holds.
Related reading

More in C
Simulating a Parking Garage with Queues and a Stack
A complete application to finish the course: a parking garage whose lanes are linked-list queues, where a car leaving from the middle of a lane needs the cars in front of it moved out onto a stack and back. Combines queues, a stack, searching and careful pointer updates.
Locating Duplicate File Names with a Binary Search Tree
Over time a disk collects files with the same name in different folders. Walk every directory, insert each file name into a binary search tree, and report a duplicate the moment a name is found already in the tree. Includes a runnable version and a real directory walk with nftw().
Infix to Postfix, and Evaluating Postfix Expressions
How does a compiler get X = A / B + C * D - F * G / Q in the right order? Convert infix expressions to postfix with an operator stack, respecting priority and parentheses, then evaluate postfix with a number stack. Fixes the classic version's missing minus sign and empty-stack bug.
The Keyboard Queue and the Function-Call Stack
Two data structures every program relies on without seeing them: the circular queue that holds the keys you type before a program reads them, and the stack that remembers where each function call must return to. Simulate both, and see how recursion builds and unwinds stack frames.
Discussion
Sign in to ask a question or share what you learned.