Data Space Animation for Learning the Semantics of C++ Pointers Amruth N. Kumar Ramapo College of New Jersey 505 Ramapo Valley Road Mahwah, NJ 07430 201 684 7712
[email protected] ABSTRACT We incorporated animation of the data space into a web-based tutor for solving problems on C++ pointers and made the tutor available to students. In evaluation of the tutor, we found that data space animation indeed helps students learn the semantics of pointers. But, it is no more effective at this than text explanation of the step-by-step execution of the program.
Categories and Subject Descriptors K.3.1. [Computing Milieux]: Computer-Assisted Instruction
General Terms Measurement, Experimentation.
Keywords Web-based tutor, C++ pointers, Bugs, Data space, Animation, Visualization, Explanation, Evaluation, Effectiveness.
1. INTRODUCTION C++ pointers are considered to be one of the hardest programming concepts to master (e.g., [1]). Students struggle with pointers, whether they use them for indirect addressing or dynamic memory management. The syntax for declaring and dereferencing pointers takes getting used to, but more than the syntax, the semantic pitfalls of pointers trumps students. In addition to understanding the additional level of indirection during assignment and referencing/dereferencing, students must understand the two types of bugs common to the use of pointers – dangling pointers and lost objects (memory leak). In each case, they must understand how the bug originates and its implications to the correctness of the program. Students need a clear model of memory locations to understand the semantics of pointers. Typically, instructors use diagrams such as in figure 1 to illustrate pointers.
Figure 1: Typical classroom illustration of a pointer Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. SIGCSE’09, March 3–7, 2009, Chattanooga, Tennessee, USA. Copyright 2009 ACM 978-1-60558-183-5/09/03…$5.00.
Figure 1 illustrates the additional level of indirection inherent to pointers, and hence the concept of referencing versus dereferencing. But, it is not quite as helpful to understand the origination of the bugs related to pointers, especially when the bugs are a result of the execution of a particular sequence of statements in the code. For example, in the following C++ code, a pointer becomes a dangling pointer because the variable to which it points goes out of scope: short * indirectPointer; { short amount = 9; indirectPointer = & amount; … } cout