Test MDX File V6
This is a Test MDX File for the Pointer Lab interactive.
Compiler Test?
Section titled “Compiler Test?”Check out this basic Hello World example:
Pass-by-Value, Pass-by-Reference, Pass-by-Pointer
Section titled “Pass-by-Value, Pass-by-Reference, Pass-by-Pointer”C++ gives you three ways to hand a variable to a function. They look almost identical at the call site but produce dramatically different memory pictures and behaviours. The component below lets you flip between the three modes and scrub through the call to see exactly what each one does.
Knowledge Check
Section titled “Knowledge Check”Default example — value = 10, function adds 5. Try each of the three modes and scrub through the phases.
C++ Pass-By Lab
See what changes — and what doesn't — when you pass by value, by reference, or by pointer.
A second example using assignment instead of addition, and a different starting value:
Pass-By Lab — Reset to Zero
See what changes — and what doesn't — when you pass by value, by reference, or by pointer.
A third example showing the pointer-only nullify action — note that even though the local pointer is cleared, value in main is untouched because the change to x itself doesn’t reach back across the frame boundary:
Pass-By Lab — Pointer Reassignment
See what changes — and what doesn't — when you pass by value, by reference, or by pointer.
The Stack and the Heap
Section titled “The Stack and the Heap”When you declare a variable normally — int x = 42; — it lives on the stack, a fast region of memory tied to the current function call. It’s automatic: the stack grows when the function is entered, shrinks when it returns, and you never write a free-statement for it.
When you write new, you’re allocating on the heap instead. The heap persists indefinitely — until you say delete — and it lives at completely different addresses from the stack. The pointer holding the heap address still lives on the stack, which is why ending the function destroys the pointer but not what it points at.
The lab below lets you build up a small program one statement at a time and see exactly what’s happening in each region.
Knowledge Check
Section titled “Knowledge Check”C++ Stack & Heap Lab
Allocate, dereference, free — and see what survives when the program ends.
© 2026 Derek Molloy, Dublin City University. All rights reserved.