C++ fundamentals · Lesson 1 of 21
Your first C++ program
What a compiled language is, the parts of a program, and cout.
C++ is a very fast language close to the hardware. Game engines (Unreal), browsers (Chrome), databases and embedded devices are written in it, and it's the favourite language of programming contests.
The big difference from JavaScript and Python is that it's compiled: before the program runs, the compiler translates all the code into a machine-code file. If there's a mistake in the code, the program won't run at all.
main.cpp (your code)
the compiler (g++)
an executable in machine code
run
When you press Run here, the server does all of these steps.
#include <iostream>
int main() {
std::cout << "Hello, SeaCode!\n";
std::cout << "2 + 3 = " << 2 + 3 << "\n";
return 0;
}Line by line:
#include <iostream>brings in the input/output library.int main()is where the program starts; it must exist.std::cout << …prints, and<<chains pieces together."\n"is a new line, and;ends each statement.return 0;means "finished without problems".
Spot the bug
This program won't compile. Which line?
Exercise
Write a program that prints exactly two lines:
I am learning C++
10 * 12 = 120 (compute the 120 in code, don't type it).
I am learning C++ 10 * 12 = 120
#include <iostream>
int main() {
return 0;
}Learn more from
Played 0 of 2 games
Sign in to save your progress and earn XP.