Test MDX File V5
This is a Test MDX File for the Pointer Lab interactive.
Pointers in C++
Section titled “Pointers in C++”A pointer is a variable whose value is the address of another variable.
Declaring a pointer with int* p = &a; stores the address of a inside p.
The expression *p (“the thing p points at”) reads the value
back from that address, interpreting the bytes through the pointer’s declared
type.
The pointer’s declared type matters. int* p = &a; tells the compiler to
treat whatever is at address &a as a four-byte int. If p actually
points at a single-byte char, the dereference reaches past the character
into whatever bytes happen to live next to it. This is a classic undefined behaviour.
Interactive Pointer Lab
Section titled “Interactive Pointer Lab”The lab below is pre-loaded with an int a = 545;, a char b = 'X';,
and a float c = 3.14;, plus a pointer p declared as int* pointing at
a. Try these in order:
- Keep the defaults and read the live
coutpanel —*pprints545. - Change the pointer’s type to
char*(still pointing ata). The same four bytes ofaare reinterpreted as a singlechar— and*pprints whatever ASCII character sits in the lowest byte. - Enable Pick via click, then click
b(the char). Now*preads a byte from'X'cleanly. - Switch to
void*— the compiler refuses to dereference. - Choose
nullptrfrom the dropdown to see the classic null-deref.
C++ Pointer Lab
Point p at a variable and see what *p produces — matching types and mismatched ones.
Here is a Class Hierarchy exercise, expanded by default …
Build the Animal Hierarchy
Build the Vehicle Hierarchy
Here is a second Class Hierarchy exercise, collapsed by default … This one models a small slice of a C++ I/O class hierarchy.
Reconstruct a C++ Stream Hierarchy
The Abstract version
Build the Shape Hierarchy
© 2026 Derek Molloy, Dublin City University. All rights reserved.