BYTE LAB — Learn C++ and Algorithms
BYTE LAB
0 / 46

Learn C++
by watching it think.

Computers don't do magic — they follow steps, one at a time. In this lab you can slow those steps down, poke them, and see exactly what the machine is doing. Nine stations. Real C++. No installing anything.

Terminal 01

      

Station 01

Variables are labelled boxes

When a program needs to remember something, it asks for a box in memory, puts a label on it, and drops a value inside. In C++ you also say what kind of thing goes in the box — and the computer holds you to it. Type anything below and watch the same value land in five different kinds of box.

Type a value and press Store.

What C++ sees

    
TIP

Press Try Hello and watch the char box: it keeps only the 'H' and throws the rest away, because a char holds exactly one character. Note the quotes too — 'H' with single quotes is one character, "H" with double quotes is a whole string. And look at the ASCII number under it: a char really is just a small integer wearing a costume, which is why 'A' + 1 gives you 'B'.

Station 02

Making choices with if

An if is a fork in the road. The computer checks one question, and takes exactly one path. Drag the slider and watch which door opens.

78
78
score >= 60 → "You passed!"
otherwise → "Keep practising!"
Live code

    
TIP

Watch line 3 as you drag. >= means "greater than or equal to", so a score of exactly 60 still passes. One tiny character changes who passes and who doesn't.

Station 03

Loops do the boring bits

Want to do something ten times? You don't write it ten times. A for loop keeps a counter, and repeats until the counter says stop. Press Run and watch BYTE walk the track — one lap per turn of the loop.

The counter starts at 1.

Live code

    
Output
(nothing yet)

Station 04

Arrays: a row of lockers

One box holds one thing. An array is a whole row of boxes sharing a name, numbered from zero. Click a locker to open it.

Click any locker.

Live code

    
TIP

The first locker is scores[0], not scores[1]. Five lockers means the last one is scores[4]. Nearly every programmer has been bitten by this — now you won't be.

Station 05

Functions are machines you build

A function takes something in, does a job, and hands something back. Build it once, use it forever. Drop a number in the hopper and watch the gears turn.

6
→
→
?
Live code

    

Station 06

The Code Lab — walk through a real program

Here are five complete C++ programs. Step through them one line at a time and watch memory change and output appear. This is exactly what a debugger does, and it is the single best way to understand code that confuses you.

Program

      
Memory
Output

1 / 1

Station 07

Your first algorithm: Bubble Sort

An algorithm is just a recipe. Bubble sort's recipe is almost silly: look at two neighbours, and if they're in the wrong order, swap them. Repeat until nothing swaps. The biggest value "bubbles" to the end each pass. Watch it happen.

PASS 0 COMPARISONS 0 SWAPS 0

Press Play to start sorting.

The whole algorithm

    
TIP

Count the comparisons for 10 bars — it's about 45. For 100 bars it would be about 4,950. Bubble sort gets slow fast. That's why the next station matters so much.

Station 09

Prove it

Eight questions. Wrong answers are fine — each one explains itself, so you learn either way. Scroll back up any time to check.

0 / 8