Every piece of hello world is load-bearing, and every piece comes back in everything you write afterwards. Click each one and find out what it is actually for.
Here is the program every programmer has written first, in every language, for fifty years. It puts one line of text on the screen. That is all it does — and it is still worth taking apart properly, because every single piece of it comes back in everything you write afterwards.
Open VS Code, make a file called hello.cpp in the folder you made last level, and type this. Type it, do not paste it. Typing it is how you find out that the compiler cares about characters you would not have noticed.
Click any highlighted piece of the program to find out what it is for.
Click any coloured part above. There are nine pieces and every one of them is load-bearing — take any of them out and the program either refuses to compile or stops making sense.
Save the file. Then in Terminal, from the folder the file is in:
$ g++ -std=c++17 -Wall hello.cpp -o hello # nothing at all happens. that is success. $ ./hello Hello, world!
The silence after the first command is the part that confuses everyone. A compiler that has nothing to say is a compiler that found nothing wrong. It does not congratulate you. It just makes the file and stops.
You will change the code, save it, run ./hello, and see the old behaviour — then spend twenty minutes wondering why your fix did nothing. You forgot to compile. Everyone does this. The habit that kills it: never run without compiling first, on one line:
$ g++ -std=c++17 -Wall hello.cpp -o hello && ./hello
The && means only if that worked. If the compile fails, it does not run the stale program — it stops and shows you the error. Use this from now on and one whole category of confusion never happens to you.
Look back at what the program does. cout puts something on the screen — that is one step in a sequence from level 3. The semicolons end each instruction, which is how the machine knows where one ends and the next begins — the literal machine from level 1, needing you to be exact. And int main() is a function from level 2: a named piece of work, with a kind of answer it hands back.
That is why the twelve levels came first. None of this is new thinking. It is the thinking you already did, written down in a notation with strict punctuation.
Remove exactly one thing: a semicolon, a brace, the #include line, one quote mark. Do not say which.
Before compiling, say out loud what you think the compiler will complain about. Then compile and read the real message together.
Do this six or seven times and something useful happens: compiler errors stop being a wall of noise and start being a small set of familiar complaints. You will meet every one of these for real in week two — and having broken it yourself on purpose, calmly, is completely different from meeting it at midnight when it is not your fault.
A compiler with nothing to say found nothing wrong. It never congratulates you.
You edit one and run the other. Saving changes nothing until you compile again.
One line, joined by &&, so you can never accidentally run yesterday’s program.
Not recall — these are the shapes an exam actually uses. Every answer below was produced by compiling and running the code, so if you disagree with one, the compiler is the one to believe.
Have a real go before revealing. Being wrong here is worth more than being right in three weeks.
You compile and Terminal prints absolutely nothing. What happened?
You fix a bug, save the file, run ./hello — and see the OLD behaviour. Why?
What is int main()?
← back to the whole C++ track · stuck on anything? ask peter.