So I'm teaching a 2nd semester freshman level C++ course at a university in an upcoming semester. The students have used arrays (though only statically allocated) and have some notion of references and pointers (but probably not much). In general, they have not done a whole lot of dealing with dynamic memory allocation and management. I'm trying to sort of harness the global intelligence of the Stack Overflow community to see, in your collective experience, what have been the most effective ways to teach things like pointers and memory management to young computer science students?
There are a lot of existing interesting StackOverflow posts on related topics:
http://stackoverflow.com/questions/92001/what-is-the-real-difference-between-pointers-and-references
I certainly have my own set of opinions on how and what I teach, but I'm really interested in how my methodology differs from yours. Some sub-questions to consider (you're certainly not limited to these):
What order would you teach things in and how would you relate the topics? "Ordinary" stack variables, followed by references, followed by pointers? Where do arrays fit in? When do you introduce the "new" keyword? etc.
What visual aids have you seen used that best express these concepts? e.g. Drawing boxes for memory locations with values inside and variables/pointers as names with arrows pointing to the boxes? Are there any particular websites or textbooks you've read that just have outstanding descriptions?
Are there particular code examples (e.g. a "swap" function) that tend to get the information across better than others?
Teach on!
Edit
In an attempt to differentiate this from some of the links I've posted:
Most of the previous SO links I've posted focus themselves very directly on pointers. Though pointers are an integral part of understanding memory behavior, I'm interested in the more overarching themes of how students understand how memory works in general. How do we best illustrate the differences between normal, pointer, and reference declaration? How do we emphasize the differences between global, stack, and heap variables? I think even getting into pushing return addresses onto the call stack is fair game too. What do you think the most important aspects of memory management are, how do you tie them all together, and how do you get this across in a coherent fashion?