Skip to content

Search is only available in production builds. Try building and previewing the site to test it out locally.

Test MDX File V5

This is a Test MDX File for the Pointer Lab interactive.

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.

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:

  1. Keep the defaults and read the live cout panel — *p prints 545.
  2. Change the pointer’s type to char* (still pointing at a). The same four bytes of a are reinterpreted as a single char — and *p prints whatever ASCII character sits in the lowest byte.
  3. Enable Pick via click, then click b (the char). Now *p reads a byte from 'X' cleanly.
  4. Switch to void* — the compiler refuses to dereference.
  5. Choose nullptr from 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.

Memorydata 0x10000x1009p at 0x100A
9 / 10 data bytes used1 free

This example assumes a 64-bit platform — pointer p stores an 8-byte address.

+0
+4
+8
p →
1009
a
545
b
c
3.14
p
0x1000
byte 0
4
8
A pointer is a variable that stores an address

Select the dereference type of the pointer p and the variable at which it points:

Pointer p

int* p = &a; // p stores 0x1000

Type Palette — drag onto memory

char8-bit
int32-bit
float32-bit
main.cpp — live
int a = 545;
char b = 'X';
float c = 3.14;
int* p = &a;
cout << p; // output: 0x1000
cout << *p; // output: 545
Try this:Start with int* p = &a and watch *p print 545. Now change the pointer type to char* without changing the target — the same four bytes of memory are reinterpreted as a single char, and *p suddenly prints a different value. Finally, set p = nullptr to see the classic null-deref crash.

Here is a Class Hierarchy exercise, expanded by default …

Class Hierarchy

Build the Animal Hierarchy

Drag class names from the pool into the slots so each class sits below its parent in the inheritance tree, then click Submit.

Inheritance Tree (base class on top)
·····
·····
·····
·····
·····
·····

Available Classes

Dog
Animal
Plant
Reptile
Vehicle
Bird
Insect
Fish
Sparrow
Cat
Mammal
Class Hierarchy

Build the Vehicle Hierarchy

Drag class names from the pool into the slots so each class sits below its parent in the inheritance tree, then click Submit.

Inheritance Tree (base class on top)
·····
·····
·····
·····
·····
·····

Available Classes

Car
Aircraft
Submarine
Motorcycle
Watercraft
Engine
Vehicle
Bicycle
Sailboat
Wheel
LandVehicle

Here is a second Class Hierarchy exercise, collapsed by default … This one models a small slice of a C++ I/O class hierarchy.

Class Hierarchy

Reconstruct a C++ Stream Hierarchy

The Abstract version

Abstract Class Hierarchy

Build the Shape Hierarchy

Drag class names from the pool into the slots so each class sits below its parent in the inheritance tree. Abstract classes are shown in italics with an amber accent — slots expecting an abstract class are pre-marked with «abstract». Click Submit when you're done.

Inheritance Tree (base class on top)
«abstract»
«abstract»
·····
·····
«abstract»
·····

Available Classes

Ellipse
Circle
Rectangle
Shape
Polygon
Pixel
Square
Curve
Triangle