Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 171 ยท Getting Started

Getting Started with C++

Learn what C++ is, where it's used and why it's still everywhere. Write, compile and run your first modern C++ program with std::println, right in your browser.

C++ is a fast, general-purpose programming language that gives you direct control over how your program uses memory and the processor, while still offering high-level tools like classes, generic code and a rich standard library. Bjarne Stroustrup began creating it in 1979 under the name "C with Classes", and it has been reshaped many times since. The C++ you'll learn here, often called modern C++ (C++17, C++20 and C++23), is safer and far more pleasant to write than the C++ of the 1990s.

This course starts from zero. You don't need to know another language first, although if you do, you'll pick things up quickly. Every lesson has live editors: you write real C++ code, press Run, and our server compiles it with GCC 15 and shows you the output a moment later.

Where C++ is used

C++ shines wherever speed, predictable performance or close contact with hardware matters. You use software written in C++ every day, often without noticing:

  • Games and game engines. Unreal Engine, most AAA game engines, and the performance-critical parts of countless games are C++. A game has about 16 milliseconds to produce each frame, and C++ lets developers control exactly where that time goes.
  • Web browsers. Chrome, Firefox and Safari are built largely in C++, including the JavaScript engines (V8, SpiderMonkey, JavaScriptCore) that run the scripts on every web page.
  • Operating systems and tools. Large parts of Windows, macOS components, compilers like Clang and GCC, and databases such as MySQL and MongoDB are written in C++.
  • Finance. Trading systems where microseconds decide profit or loss rely heavily on C++.
  • Embedded systems. Cars, medical devices, drones, routers and factory robots run C++ on small processors with little memory.
  • Science and high-performance computing (HPC). Physics simulations, weather models and machine-learning libraries (the fast cores of TensorFlow and PyTorch) are C++ under the hood.
  • Desktop applications. Photo and video editors, music software, CAD tools and office suites.

The common thread: these programs must be fast, use resources carefully, and often run for years. C++ was designed for exactly that.

Why learn C++?

C++ has a reputation for being hard, and it's honest to say it's a big language. But it rewards you well:

  • Performance. C++ compiles to native machine code. There's no virtual machine and no garbage collector pausing your program at random moments.
  • Control. You decide when objects are created and destroyed and how data is laid out in memory. That control is why C++ runs everywhere from microcontrollers to supercomputers.
  • Zero-cost abstractions. You can write clean, high-level code (containers, algorithms, classes) that compiles to code as fast as hand-written low-level loops. "What you don't use, you don't pay for" is a core C++ principle.
  • Deep understanding. Learning C++ teaches you how computers really work: memory, pointers, the stack and the heap, compilation and linking. That knowledge makes you better in every other language.
  • Careers. C++ jobs in games, finance, embedded systems and infrastructure are plentiful and well paid, and the language isn't going anywhere.

Note: C++ is a different language from C, C# and Java, even though they look similar. C++ grew out of C and can still use most C code, but modern C++ style looks very different from C. You'll compare the two in a later lesson.

Your first program

Here is a complete C++ program. Press Run and watch the output appear below the editor:

C++ Hello, C++

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with std::cin or std::getline), it gets the next line from this box.

The very first run takes a couple of seconds because the code is sent to our server, compiled into a real program, and then executed. Let's look at each line.

  • #include <print> brings in the part of the standard library that knows how to print text. C++ has very few built-in features for input and output; they live in library headers that you include at the top of your file.
  • int main() starts the main function. Every C++ program has exactly one main, and that's where execution begins. The int means main returns a whole number to the operating system: 0 means "everything went fine".
  • The curly braces { } mark the body of main, the instructions it runs.
  • std::println("Hello, C++!"); prints the text and then moves to a new line. Text in double quotes is a string literal. The std:: prefix says that println belongs to the standard library.
  • The semicolon ; ends the statement. Forgetting it is the most common beginner error, and the compiler will tell you right away.

You might notice there's no return 0; at the end. main is special: if it reaches its closing brace, C++ acts as if it returned 0. You'll still see return 0; in a lot of code, and writing it is perfectly fine.

Printing more than one line

A program runs its statements from top to bottom, one after another. Each std::println call prints its own line:

C++ Several lines

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with std::cin or std::getline), it gets the next line from this box.

The last two lines show the real power of std::println. Each pair of braces {} in the text is a placeholder, and the values after the text fill the placeholders in order. C++ calculates 6 * 7 before printing, so the output says 6 times 7 is 42.. You'll learn every formatting trick in Printing Output.

Try changing the numbers, adding a line, or deleting a semicolon to see what the compiler says. Error messages from C++ compilers can look scary at first, but the first error: line usually tells you exactly what's wrong and where. Delete the semicolon in the very first program and GCC reports main.cpp:4:32: error: expected ';' before '}' token: the file, line 4, column 32, and what it expected to find.

The same program with iostream

std::println arrived in C++23. Before that, C++ programs printed with iostreams: std::cout and the << operator. You'll see this style in nearly every book, tutorial and codebase written in the last 30 years, so you need to read it fluently:

C++ Hello with std::cout

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with std::cin or std::getline), it gets the next line from this box.

  • #include <iostream> brings in the input/output streams.
  • std::cout (say "see-out", for "character output") is the standard output stream.
  • << sends values into the stream, left to right. You can chain as many as you like.
  • \n is an escape sequence for "new line". Unlike println, cout doesn't add a line break for you.

Both styles produce the same output. In this course we mostly use std::println because it's shorter, faster and harder to get wrong, but we'll use std::cout too, and the Printing Output lesson covers both in depth.

Tip: If you install an older compiler on your own computer and #include <print> fails, the compiler doesn't support C++23 yet. Switch to the <iostream> version, or install GCC 14+, Clang 18+ or a recent Visual Studio 2022. How C++ Works explains how to set up a compiler.

Running C++ in this course

Every editor on this site works the same way:

  1. You edit the code in the editor. It's a single file called main.cpp.
  2. When you press Run, the code is sent to our server and compiled with GCC 15.2 using the C++23 standard and warnings switched on (-Wall -Wextra).
  3. If compilation succeeds, the program runs and its output appears below the editor. If it fails, you see the compiler's error messages instead.
  4. Programs that read input get it from the Input box, which you'll use in Reading User Input.

Each run is a fresh program: nothing is remembered between runs, and programs can't access the internet. Runs are also time-limited, so an accidental infinite loop just gets stopped.

Here's a slightly bigger program that uses a few things you'll learn soon. Don't worry about understanding every line yet; just run it and change the values:

C++ A small taste of C++

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with std::cin or std::getline), it gets the next line from this box.

This program stores values in variables (language, year, scores), loops over a list of numbers with a range-based for loop, and prints the results. The text after // is a comment, a note for humans that the compiler ignores. Each of these ideas gets its own lesson.

How this course is organized

The course moves in small, steady steps:

  1. Getting Started: how C++ programs are built, the basic syntax, comments, output and input.
  2. Variables, types and operators: storing and calculating with data.
  3. Strings, control flow, arrays and vectors: making decisions, repeating work and handling collections.
  4. Functions, pointers and memory: organizing code and understanding what really happens in memory.
  5. Object-oriented and generic programming: classes, inheritance, templates and concepts.
  6. The standard library: containers, algorithms, ranges, smart pointers, files, threads and more.
  7. Projects and practice: complete programs, exercises and interview questions.

Each lesson ends with a short quiz. Don't skip the editors: the fastest way to learn C++ is to change examples, break them, read the error, and fix them again.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Where does a C++ program start running?

    Every C++ program has exactly one main function, and execution begins there. #include lines are processed before compilation, not run.
  2. 2. What does std::println("{} + {} = {}", 2, 3, 2 + 3); print?

    Each {} is replaced by the next value in order. The expression 2 + 3 is calculated first, so the last placeholder becomes 5.
  3. 3. You write std::cout << "Hi"; twice in a row. What appears?

    std::cout never adds a line break by itself. You need \n (or std::endl) to move to a new line.
  4. 4. A main function reaches its closing brace without a return statement. What happens?

    main is the one function where falling off the end is the same as return 0;, which means success.
  5. 5. Why does the code need #include <print> before using std::println?

    C++ keeps input and output in the standard library. Including the <print> header declares std::println so the compiler knows it exists.

Summary

  • C++ is a fast, compiled, general-purpose language used in games, browsers, operating systems, finance, embedded devices and scientific computing.
  • Modern C++ (C++17/20/23) combines low-level control with high-level, safe abstractions.
  • Every program has one main function where execution starts; reaching its end means return 0.
  • #include <print> and std::println("text {}", value) print a line with placeholders filled in.
  • #include <iostream> and std::cout << ... << '\n' is the classic style you'll see everywhere.
  • Statements end with a semicolon, and the compiler tells you when something is wrong.

Next: How C++ Works: Compiling and Linking, where you'll see what happens between pressing Run and seeing your output.