Let's break it down:

int a = 10, *p1, *p2;  // nothing special
p1 = &a;               // p1 now holds the address of a. printf("%d", *p1) would print 10, as it is the current value of a.

// in this point, printf("%d-%d", *p1,a); would print 10-10 (printf("%d",*p2); is UB as p2 is uninitialized)

*p1 = 25;              // remember that p1 = &a, meaning that now a = 25. Basically you changed (the variable) a, using a pointer instead of changing it directly.
p2 = p1;               // p2 now holds the value of p1, meaning it too points to a

// in this point, printf("%d-%d-%d", *p1,*p2,a); would print 25-25-25

*p2 = 12;              // *p2 = 12, and so does *p1, and so does a

// in this point, printf("%d-%d-%d", *p1,*p2,a); would print 12-12-12

 printf("%d", *p1);

You should remember that a is an int that holds an integer value, and p1,p2 are int * that hold the address of an int. After p1 = &a, every change to a would mean that *p1 is changed too, since *p1 is actually *(&a) [which is...a]. After p2 = p1, the same holds for p2.


I thought originally that code in general executes from top to bottom.

Well, it does :)

Answer from CIsForCookies on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › c language › c-pointers
Pointers in C - GeeksforGeeks
The data type indicates the type of variable the pointer can point to. For example, "int *ptr;" declares a pointer to an integer.
Published   3 weeks ago
🌐
w3resource
w3resource.com › c-programming-exercises › pointer › index.php
C programming exercises: Pointer - w3resource
October 16, 2025 - Pointer : Show the basic declaration of pointer : ------------------------------------------------------- Here is m=10, n and o are two integer variable and *z is an integer z stores the address of m = 0x7ffd40630d44 *z stores the value of m ...
Discussions

Best Pointers Explanation
Q: Where do you live? A: At , , . That's a pointer. Now, at that address, there is a building with many floors. Q: On what floor do you live? A: Floor X. That's a pointer. Now, at that address, there are many apartments. Q: What's your apartment's number? A: It's Y. That's a pointer. A program manipulates data. That data is stored somewhere in memory. To access that memory we need a reference to it, that's what variables are. But sometimes, we need to manipulate the location of the memory itself. That's what pointers do, they are variables that contain the location information. Just like Amazon will ask for your house address so that it can deliver your package, you don't send your house to Amazon, only its location information. An index in an array is a pointer. An offset on the stack is a pointer. A virtual 64-bits address is a pointer. etc. More on reddit.com
🌐 r/C_Programming
53
45
December 15, 2023
Dereferencing a char Pointer in C
Initializing a pointer creates space for the pointer itself but not for the resulting value... So char* p doesn't actually create the 1 byte needed for a char anywhere in memory. You have to do that explicitly in C. Add a malloc statement for example. https://www.gnu.org/software/libc/manual/html_node/Basic-Allocation.html Also if you malloc don't forget to free! Welcome to C, where the memory manager is you, dear coder :) #include #include int main(void) { char *p = (char*) malloc(sizeof(char)*1); *p = 'p'; printf("%c\n", *p); free(p); return 0; } Does this make sense? More on reddit.com
🌐 r/CodingHelp
3
3
April 30, 2021
pointers in C
Here's a book: https://www.amazon.com/Understanding-Pointers-C-Yashavant-Kanetkar/dp/8176563587 int x = 5; int *p = &x; printf("%p\n", p); printf("%d", *p); A pointer (at least in C) is a variable that stores a memory address. I'll repeat this again: pointers are VARIABLES. However, instead of storing some kind of integer or float value, pointers hold memory addresses. On the first line above, I've defined a variable 'x' and assigned it to the value 5. Here, we're storing 5 in a memory block, let's call this block "x", which will hold two things: 1) the value 5 and 2) the address of the block. The address of the block just tells us where the value is stored on your computer, just like your home address tells a person where you may live in your town. In programming, your computer (more accurately, your computer memory) is the town. A pointer is more akin to an address book, but a "book" that has a single page with only one address. A pointer comes with two operators: 1) the address operator (the ampersand &) and the deference operator (the pound symbol *). The address operator gives you the address of where a particular value is stored in memory while the dereference operator gives you the actual value. The * symbol is also used to declare that a specific variable is a pointer in C. Going through the short snippet of code above, in line 2, I'm declaring a pointer with the variable name 'p' and then assigning it to the memory address of x (hence why I use &). On the third line, I'm printing the pointer (which stores the memory address) and that will ultimately display an address (in hexadecimal in the terminal). On the last line, instead of printing the address/pointer, I dereferenced the pointer to get the value stored at the specified address using the * operator. Here's another analogy I'll end off on: Let's say I have a class of 5 people and I've scattered random objects across the room. I give each person a sticky note that describes where they can find an object in the room. In this scenario, the sticky notes would be the pointers that hold the address of an object in the room. More on reddit.com
🌐 r/C_Programming
22
12
August 18, 2022
Can someone explain pointers (in C) to me like I'm 10?
a pointer is an address More on reddit.com
🌐 r/learnprogramming
45
35
July 27, 2011
Top answer
1 of 5
7

Let's break it down:

int a = 10, *p1, *p2;  // nothing special
p1 = &a;               // p1 now holds the address of a. printf("%d", *p1) would print 10, as it is the current value of a.

// in this point, printf("%d-%d", *p1,a); would print 10-10 (printf("%d",*p2); is UB as p2 is uninitialized)

*p1 = 25;              // remember that p1 = &a, meaning that now a = 25. Basically you changed (the variable) a, using a pointer instead of changing it directly.
p2 = p1;               // p2 now holds the value of p1, meaning it too points to a

// in this point, printf("%d-%d-%d", *p1,*p2,a); would print 25-25-25

*p2 = 12;              // *p2 = 12, and so does *p1, and so does a

// in this point, printf("%d-%d-%d", *p1,*p2,a); would print 12-12-12

 printf("%d", *p1);

You should remember that a is an int that holds an integer value, and p1,p2 are int * that hold the address of an int. After p1 = &a, every change to a would mean that *p1 is changed too, since *p1 is actually *(&a) [which is...a]. After p2 = p1, the same holds for p2.


I thought originally that code in general executes from top to bottom.

Well, it does :)

2 of 5
5

Address values used here is totally arbitrary, just for example

int a = 10, *p1, *p2;

the previous line declare one variable of type int (a) and two pointers to int (p1 and p2)

memory after the previous line

address | memory | variable
1050    | 10     | a
1054    | xxx    | p1
1058    | xxx    | p2

p1 = &a; // &a is address of a, ie here, 1050

memory after the previous line

address | memory | variable
1050    | 10     | a
1054    | 1050   | p1 
1058    | xxx    | p2
  • p1 stores "1050"; *p1, ie value stored at address stored inside p1, is 10

*p1 = 25; // *p1 means value stored at address stored inside p1

memory after the previous line

address | memory | variable
1050    | 25     | a
1054    | 1050   | p1 
1058    | xxx    | p2
  • p1 stores "1050"; *p1, ie value stored at address stored inside p1, is now 25

p2 = p1;

memory after the previous line

address | memory | variable
1050    | 25     | a
1054    | 1050   | p1 
1058    | 1050   | p2
  • p1 stores "1050"; *p1, ie value stored at address stored inside p1, is 25
  • copy values stored inside p1 in p2; so p2 points to a, ie stores address "1050"

*p2 = 12;

memory after the previous line

address | memory | variable
1050    | 12     | a
1054    | 1050   | p1  
1058    | 1050   | p2

printf("%d", *p1); // Print value stored at address stored inside p1

What we can see here:

  • p1 and p2 are pointers: they store address of variable
  • & (like in &a): returns address of a variable
  • * in declaration (like in int *p1): declare pointer to a variable (here to a int variable)
  • * in expression (like in *p1 = 25): access to value stored at address stored in pointer

You can see different addresses and values :

printf("address of a: %p\n", &a);
printf("address of p1: %p\n", &p1);
printf("address of p2: %p\n", &p2);

// address stored inside p1 (ie value stored inside p1)
printf("address stored inside p1: %p\n", p1);
// address stored inside p2 (ie value stored inside p2)
printf("address stored inside p2: %p\n", p2);

printf("value of a: %d\n", a);
printf("value pointed by p1: %d\n", *p1);
printf("value pointed by p2: %d\n", *p2);
🌐
W3Schools
w3schools.com › c › c_pointers_arrays.php
C Pointers and Arrays
Well, in C, the name of an array, is actually a pointer to the first element of the array. Confused? Let's try to understand this better, and use our "memory address example" above again.
🌐
Programiz
programiz.com › c-programming › c-pointers
C Pointers (With Examples)
Here, 5 is assigned to the c variable. And, the address of c is assigned to the pc pointer. To get the value of the thing pointed by the pointers, we use the * operator. For example: int* pc, c; c = 5; pc = &c; printf("%d", *pc); // Output: 5
🌐
TechVidvan
techvidvan.com › tutorials › pointers-in-c-language
Pointers in C with Examples - TechVidvan
July 17, 2021 - In C, we can use an array of pointers to make your coding simple and easy. ... In the above example, we have declared point as an array of 4 integer pointers.
🌐
W3Schools
w3schools.com › c › c_pointers.php
C Pointers
In the example above, we used the pointer variable to get the memory address of a variable (used together with the & reference operator). You can also get the value of the variable the pointer points to, by using the * operator (the dereference operator):
Find elsewhere
🌐
freeCodeCamp
freecodecamp.org › news › pointers-in-c-programming
How to Use Pointers in C Programming
May 3, 2023 - A pointer can also point to another pointer variable. This is known as a "pointer to a pointer". We declare a pointer to a pointer by using two asterisks **. For example: ... Here, q is a pointer to a pointer. It points to the address of the p variable, which in turn points to the address of the x variable
🌐
Wikipedia
en.wikipedia.org › wiki › Pointer_(computer_programming)
Pointer (computer programming) - Wikipedia
4 days ago - Another common use of pointers is to point to dynamically allocated memory from malloc which returns a consecutive block of memory of no less than the requested size that can be used as an array. While most operators on arrays and pointers are equivalent, the result of the sizeof operator differs. In this example, sizeof(a) will evaluate to 5 * sizeof(int) (the size of the array), while sizeof(ptr) will evaluate to sizeof(int *), the size of the pointer itself.
🌐
Dremendo
dremendo.com › c-programming-tutorial › c-pointer
Pointer in C Programming | Dremendo
The & operator is used to store the address of variable a in pointer variable *x using the statement x=&a. So we can say that the variable x points to the value of the variable a by storing its address. Note: The above memory addresses are imaginary address used for explaining the pointer. The actual address varies from computer to computer. To access the value of a variable using a pointer, use the * operator with the pointer variable. See the examples ...
🌐
Yale University
cs.yale.edu › homes › aspnes › pinewiki › C(2f)Pointers.html
C/Pointers
Because array names act like pointers, they can be passed into functions that expect pointers as their arguments. For example, here is a function that computes the sum of all the values in an array a of size n:
🌐
Steve's Data Tips and Tricks
spsanderson.com › steveondata › posts › 2025-03-05
The Complete Guide to C Pointers: Understanding Memory and Dereferencing – Steve’s Data Tips and Tricks
March 5, 2025 - The pointer variable pScore contains the value 1000 (the address of score) and is stored at its own location (address 2000 in this example).
🌐
IncludeHelp
includehelp.com › c-programs › c-programs-pointers-solved-examples.aspx
C Pointers Example Programs, Pointer Programs in C
Here are the lists of some solved c programming pointers solved programs/examples for your practice, all programs have source code with output and explanation. This section contains solved programs on pointers, pointers with simple variable, pointers with conditional and control statements, array and pointers, pointers with strings, structure and unions. Program to create, initialize, assign and access a pointer variable.
🌐
BYJUS
byjus.com › gate › pointers-in-c
Pointers in C
August 1, 2022 - In case we don’t initialise the pointers in any C program and start using it directly, the results can be pretty unpredictable and potentially disastrous. We use the & (ampersand) operator to get the variable’s address in the program. We place the & just before that variable’s name whose address we require. Here is the syntax that we use for the initialisation of a pointer, ... Let us look at an example of how we can use pointers for printing the addresses along with the value.
🌐
TutorialsPoint
tutorialspoint.com › cprogramming › c_pointers.htm
Pointers in C
The value of the variable which is pointed by a pointer can be accessed and manipulated by using the pointer variable. You need to use the asterisk (*) sign with the pointer variable to access and manipulate the variable's value. In the below example, we are taking an integer variable with ...
🌐
Simplilearn
simplilearn.com › home › resources › software development › pointers in c: a one-stop solution for using c pointers
Pointers in C: A One-Stop Solution for Using C Pointers
June 23, 2025 - A pointer in C is a variable pointing to the address of another variable. Explore C Pointer's ✓ types ✓ advantages ✓ disadvantages, and more. Start learning!
Address   5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
🌐
Suchprogramming
suchprogramming.com › fun-with-pointers
Such Programming - Fun With Pointers
Pointers are one of the most misunderstood concepts in C but also one the most powerful tools it provides. In general they are just numbers in memory like everything else, but their value is interpreted as an address to other data. In this document I’ll attempt to demystify the arcane pointer and show some practical examples ...
🌐
Mppolytechnic
mppolytechnic.ac.in › mp-staff › notes_upload_photo › CS52024-03-2020.pdf pdf
Pointers in C Programming with examples
hold the address of int variable, similarly a pointer declared with float data type can hold the address · of a float variable. In the example below, the pointer and the variable both are of int type.
🌐
Upgrad
upgrad.com › home › tutorials › software & tech › function pointer in c
Function Pointer in C with Examples
August 26, 2025 - In C, dereferencing a function pointer is done by calling the pointer as if it were the function itself. This can be done either implicitly or explicitly: Implicit Dereferencing: When you call a function through a pointer without using the dereference operator * (because it's implied). Explicit Dereferencing: Using the dereference operator * before calling the function. Let’s look at both methods with examples.