Skip to content

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

Test MDX File V4

This is a Test MDX File for my Code Output setup for Code Cloze and Code Output.

A component with gaps in the source code and decoy pills. Added a “reset” option when the answers are incorrect as it’s difficult to drag snippets back to the pool.

Code Cloze
C++

Complete the Hello World Program

Drag snippets from the pool into the blanks so the program produces the output shown, then click Submit.

1#include <·····>
2using namespace ·····;
3
4int main() {
5 ····· << "Hello, world!";
6 return ·····;
7}
Expected Output
Hello, world!

Available Snippets

iostream
printf
cout
System
std
stdio.h
NULL
0
void

These exercises ask you to read a short snippet and choose the terminal output it produces.

Here is a Code Output exercise (C++), expanded by default … example division example. Note the output uses \n to place code on different lines. No syntax highlighting possible.

Code Output
C++

Integer Division vs. Floating Point

Read the code below, then choose the terminal output it produces and click Submit.

1#include <iostream>
2using namespace std;
3
4int main() {
5 int a = 7;
6 int b = 2;
7 cout << a / b << endl;
8 cout << (double)a / b << endl;
9 return 0;
10}
stdout
3.5
3.5
stdout
3
3
stdout
3
3.5
stdout
3.5
3

Here is a Code Output exercise (Rust), collapsed by default … The && is a little complex in the closure (pointer to pointer!) for the filter method. The initial code exposed the correct answer automatically when an incorrect answer was chosen. This version tracks incorrect answers.

Code Output
Rust

Iterator Chain Output

Lab: Bitwise Operations on 8-bit unsigned int (uint8_t)

Click bits on A and B, choose an operation, and the result updates live.

Bit #
7
6
5
4
3
2
1
0
A
B
A = 25 0x19B = 5 0x05
A & BBitwise AND
A
0
0
0
1
1
0
0
1
B
0
0
0
0
0
1
0
1
A & B
0
0
0
0
0
0
0
1
Try this:Click Textbook values to load A=25, B=5 and step through each operation to match the chapter's output table. Then try A & B with B set to 0000 1111 to isolate the low nibble of A — a classic masking idiom.

The lab below is pre-loaded with the textbook example: float a = 25.0;, int b = 545;, and double c = 123.0;. Drag any type from the palette onto the memory strip to allocate it. Click a placed variable to rename it or change its value.

C++ Memory Lab

Drag a type onto memory and watch the variable claim the bytes its size demands.

Memorybase = 0x1000
16 / 16 bytes used0 free
+0
+4
+8
+C
a
25.0
b
545
c
123.0
byte 0
4
8
12

Type Palette — drag onto memory

bool8-bit
char8-bit
short16-bit
int32-bit
unsigned int32-bit
long64-bit
unsigned long64-bit
float32-bit
double64-bit
integer types
floating point
character
boolean

Declared variables

TypeNameValueAddressSize
floata25.00x10000x10034 bytes (32-bit)
intb5450x10040x10074 bytes (32-bit)
doublec123.00x10080x100F8 bytes (64-bit)
Try this:Click Textbook example to load a, b, c. Then drag a char onto memory — notice it claims a single byte, same as a bool, while double claims eight. Click any placed variable to rename it or change its value. With 16 bytes of memory there's no room for all five textbook variables at once — that's the point: char and bool are cheap, double is expensive.

End Tests…