I'll hold a little presentation about C-Pointers in a small group of people with beginners programming skills, with no CS background. Just people who would like to learn something about coding and prefer a practical hands-on approach. In fact, they are using the C-Language to do so.
We are about to introduce pointers and I am very careful about the scope for the first introduction, since pointers can be quite overwhelming and confusing for the uninitiated.
So I am wondering, how would you approach this topic to make it fun and interesting? Do you have great examples that really help people to understand the concept of pointers?
Hint: The audience doesn't know about strings and arrays yet.
Scope-wise, here is what I've got so far:
Example: A problem that shows the limitation C without pointers and why we need something more elaborate.
- Call by reference vs Call by value example?
Very short introduction what a pointer is and how it is denoted in C. (* and & operators )
The difficult part: How does a pointer work? Or: How to explain a technical problem to non-technical people?
- Looking for a real work example for a referencing system. Is a library a good example?
- What is memory and how does it interact with our code and variables?
- How does a variable look like in memory? (memory allocation)
- How is this variable accessed? (address referencing)
- How can I use a pointer to access memory?
- In dire hope, people can follow this train of thought:
- Live example and practice
Things I would like to omit for a part2:
- Null-Pointer
- Pointer on Pointers
- Pointer arithmetic
- Adresses vs. Pointers
- Structs
- Arrays
malloc
would probably be a fine idea. What is this thing thatmalloc
returned? Why can I use it just like an array? Call by reference is probably too confusing an example before your students know about pointers (unless you're using C++, which has a nice alias syntax). One important thing is to be honest about C's memory model, don't perpetuate the “pointers are hard” FUD. – amon Feb 19 at 10:45int
for example spanned four boxes.. achar
only one). He then had a student point at a box and used his slides to show what incrementing did by having the student point at another box. I think he executed it really well and it got the basic understanding across. – Simon Whitehead Feb 19 at 12:42