<p>Pointers are simply variables which are used to store  memeory addresses of another variables. 
for example suppose we have a integer variable 
 int a =10;
then the value 10 i.e. is stored at a memory cell which can be accessed with the help of a pointer. With the help of pointer we can directly access the value the variable to which the pointer is pointing.</p>

CC BY-SA 3.0
2017-06-19T15:34:13.760Z
Welcome to CSE! OP isn't confused about the material.  He is asking how you might explain this to students so that a classroom full of kids will remember and understand.
Ben I.
CC BY-SA 3.0
2017-06-19T15:29:55.620Z
2017-06-19T15:29:55.620Z
Prasang Thakur
<p>A prerequisite to understanding pointers is a basic understanding of memory. At least on the broadest level, students need to know that when they declare a variable in their programs, that variable is stored somewhere, so they can use it, access it, update it, etc. Where that variable is stored also has some address, so it can be located (specific addressing techniques need not be introduced yet). The specifics of heap v. stack, memory size (int v. long long), and other such concepts are not necessary to understand what a pointer is (but they certainly would help). </p>

<p>All this background established, here is the easy way to think of pointers:</p>

<blockquote>
  <p>A pointer is a variable that contains an address of a variable.</p>
</blockquote>

<p>Simple enough on the surface. That sentence comes from Chapter 5 of K&amp;R (<em>The C Programming Language</em> by Kernighan and Ritchie). This chapter has a great explanation of pointers and arrays, and I would highly recommend it for an understanding of pointers, at least in the context of C. One key point for C is the following:</p>

<blockquote>
  <p>Since C passes arguments to functions by value, there is no direct way
  for the called function to alter a variable in the calling function.
  ... Pointer arguments enable a function to access and change objects
  in the function that called it.</p>
</blockquote>

<p>Now, to get into the details of pointer arithmetic, passing by reference, syntactic sugar vis-a-vis arrays, pointers do become more complicated. However, always keep in mind the simple definition that gets at their essence: pointers store addresses for other locations in memory.</p>

CC BY-SA 3.0
2017-06-17T19:19:55.607Z
2017-06-17T19:28:44.270Z
2017-06-17T19:28:44.270Z
Peter
<p>I set the stage from the beginning. When we first do variables, I draw a big box and call it the computers memory and then draw a small box of memory and say "it's at some address" (having already explained that memory is set up so you can identify each piece with a number) so when we say:</p>

<p><code>x = 20</code> (or <code>int x = 20</code> or whatever)</p>

<p>I draw something like:</p>

<pre>
x
100
____
|   |
|   |
-----
</pre>

<p>explaining that we have a block of memory at location 100 large enough to store an int (in this case) and we can get to it using the identifier x.</p>

<p>then </p>

<p><code>x=10</code> takes the 10 and stores it in the memory</p>

<p>and </p>

<p><code>a = x + 5</code>   looks to see that x is an identifier to memory 100, we get the 10 then add 5 and then store it in the box referred to by a (which is at memory location 108.</p>

<pre>
x         a
100       108  
____      ____
|   |     |   |
|10 |     | 20|
-----     -----
</pre>

<p>This sets the stage for pointers later on. When we get to pointers, we merely have to explain that the box holds a number that refers to another memory address or location:</p>

<pre>

*p             i
100            108
-------        ------
| 108 |        | 49 |
|     | -----> |    |
-------        -------
</pre>

<p>all the while using lots of drawings and arrows. </p>

<p>Also, when we talk about functions, I don't formally describe the stack but talk about it and then the memory for parameters and locals is in a subsection of memory allocated for that function call.</p>

CC BY-SA 3.0
2017-06-17T20:13:21.277Z
2017-06-19T00:17:27.730Z
2017-06-19T00:17:27.730Z
Mike Zamansky
<p>How would you explain pointers and their use to high school students with some prior knowledge in programming, mainly in Python, but very limited knowledge of C? </p>

<p>Note that this isn't a duplicate of <a href="https://cseducators.stackexchange.com/questions/299/simple-pointer-examples-in-c">Simple Pointer Examples in C</a>, because here I'm asking for an explanation of how they work, not an example of them working.</p>

CC BY-SA 3.0
2017-06-17T20:06:21.337Z
Please clarify what you mean by a explanation that does not include an example. Otherwise, this may be a dup.
 My answer in https://cseducators.stackexchange.com/questions/299/simple-pointer-examples-in-c contains an explanation of an example.
hotpaw2
CC BY-SA 3.0
2017-06-19T11:22:17.420Z
Does this have to be in C? C is heavily criticized for its design wrt memory management, pointers in particular. If you could avoid using C, there are plenty of languages where some of the problems endemic to it have been avoided, for example, OCaml, Pascal, Go, even Forth to some degree.
wvxvw
<secondary-education><pointers>
Explaining pointers to highschoolers
# Explaining pointers to highschoolers

(Asked by: username_0 on 2017-06-17)

How would you explain pointers and their use to high school students with some prior knowledge in programming, mainly in Python, but very limited knowledge of C?

Note that this isn't a duplicate of [Simple Pointer Examples in C](https://cseducators.stackexchange.com/questions/299/simple-pointer-examples-in-c), because here I'm asking for an explanation of how they work, not an example of them working.

**Tags:** secondary-education, pointers

> **Comments:**
> **username_1**: Please clarify what you mean by a explanation that does not include an example. Otherwise, this may be a dup.  My answer in https://cseducators.stackexchange.com/questions/299/simple-pointer-examples-in-c contains an explanation of an example.  
> **username_2**: Does this have to be in C? C is heavily criticized for its design wrt memory management, pointers in particular. If you could avoid using C, there are plenty of languages where some of the problems endemic to it have been avoided, for example, OCaml, Pascal, Go, even Forth to some degree.  

---

## 3 answers

### Answer by username_5 on 2017-06-17. Score: 9 | Accepted answer

A prerequisite to understanding pointers is a basic understanding of memory. At least on the broadest level, students need to know that when they declare a variable in their programs, that variable is stored somewhere, so they can use it, access it, update it, etc. Where that variable is stored also has some address, so it can be located (specific addressing techniques need not be introduced yet). The specifics of heap v. stack, memory size (int v. long long), and other such concepts are not necessary to understand what a pointer is (but they certainly would help).

All this background established, here is the easy way to think of pointers:

> A pointer is a variable that contains an address of a variable.

Simple enough on the surface. That sentence comes from Chapter 5 of K&R (*The C Programming Language* by Kernighan and Ritchie). This chapter has a great explanation of pointers and arrays, and I would highly recommend it for an understanding of pointers, at least in the context of C. One key point for C is the following:

> Since C passes arguments to functions by value, there is no direct way
> for the called function to alter a variable in the calling function.
> ... Pointer arguments enable a function to access and change objects
> in the function that called it.

Now, to get into the details of pointer arithmetic, passing by reference, syntactic sugar vis-a-vis arrays, pointers do become more complicated. However, always keep in mind the simple definition that gets at their essence: pointers store addresses for other locations in memory.


---

### Answer by username_6 on 2017-06-17. Score: 6

I set the stage from the beginning. When we first do variables, I draw a big box and call it the computers memory and then draw a small box of memory and say "it's at some address" (having already explained that memory is set up so you can identify each piece with a number) so when we say:
x = 20 (or int x = 20 or whatever)
I draw something like:

x
100
____
|   |
|   |
-----

explaining that we have a block of memory at location 100 large enough to store an int (in this case) and we can get to it using the identifier x.
then 
x=10 takes the 10 and stores it in the memory
and 
a = x + 5   looks to see that x is an identifier to memory 100, we get the 10 then add 5 and then store it in the box referred to by a (which is at memory location 108.

x         a
100       108  
____      ____
|   |     |   |
|10 |     | 20|
-----     -----

This sets the stage for pointers later on. When we get to pointers, we merely have to explain that the box holds a number that refers to another memory address or location:


*p             i
100            108
-------        ------
| 108 |        | 49 |
|     | -----> |    |
-------        -------

all the while using lots of drawings and arrows. 
Also, when we talk about functions, I don't formally describe the stack but talk about it and then the memory for parameters and locals is in a subsection of memory allocated for that function call.


---

### Answer by username_3 on 2017-06-19. Score: 1

Pointers are simply variables which are used to store memeory addresses of another variables.
for example suppose we have a integer variable
int a =10;
then the value 10 i.e. is stored at a memory cell which can be accessed with the help of a pointer. With the help of pointer we can directly access the value the variable to which the pointer is pointing.

> **Comments:**
> **username_4**: Welcome to CSE! OP isn't confused about the material.  He is asking how you might explain this to students so that a classroom full of kids will remember and understand.  

---

