Thuta Learning
C++
BasicProgrammingBeginner

C++ Home: Start Here

C++Lesson 115 min

What you'll walk away with

  • Say in one sentence what kind of language C++ is and name three kinds of software built with it
  • Read a complete small C++ program and predict what it prints
  • Find your way around the five chapters and 35 lessons of this course
  • Study each lesson by predicting, typing, breaking things on purpose and compiling with warnings on

Explain it simply

Explain it simply

C++ is a programming language for writing programs that run directly on the processor, with no interpreter in between. You write instructions in a plain text file ending in .cpp, a compiler translates that file into machine code once, and the result is a program that starts instantly and runs fast. That is why C++ sits underneath game engines, web browsers, databases and the software inside cars and cameras.

C++ grew out of C, so it keeps C's speed and close-to-the-hardware control, but it adds tools for expressing bigger ideas: text that manages its own memory, lists that grow, classes that bundle data with behavior, and templates that let one piece of code work with many types. This course teaches modern C++, the C++20 standard, from the very first line.

Problem → Why → Solution

The problem: from the outside, C++ looks enormous

Search for C++ and you meet a wall: pointers, templates, move semantics, undefined behavior, five ways to initialize a variable, and forum answers from 2005 sitting next to answers from last year. All five lines below are legal C++ and each creates a variable holding 5. Nobody tells you which one to use.

Many beginners stop here, or they pick up a random mix of old and new habits, such as raw new and delete everywhere, that they later have to unlearn.

five_ways.cpp
int a = 5;     // copy initialization, inherited from C
int b(5);      // direct initialization
int c{5};      // brace initialization (C++11)
int d = {5};   // copy-list initialization
auto e = 5;    // the compiler deduces the type (C++11)

Why an order matters in C++

C++ has kept almost every feature it ever had, so that code written decades ago still compiles. That compatibility is valuable for industry but confusing for learners, because old and modern styles both look 'correct'. This course follows a path that starts from modern defaults, such as std::string instead of character arrays and smart pointers instead of manual delete, so the first habits you form are the ones current codebases expect. By the Variables lesson you will know which of the five lines above to prefer, and why.

Core concept: C++ in four ideas

1. Compiled to native code

Your .cpp file is translated into machine instructions for one kind of processor and operating system before it runs. There is no virtual machine or interpreter at runtime, which is where much of C++'s speed comes from, and also why you recompile for each platform.

2. Statically typed

Every variable has a type the compiler knows, such as int, double or std::string. Mistakes like putting text where a number belongs are rejected before the program ever runs.

3. Zero-overhead abstractions

Features such as std::string, std::vector and classes let you write at a high level, and the compiler turns them into code about as fast as hand-written low-level code. The guiding rule is that you do not pay for features you do not use.

4. Defined by a standard

C++ is defined by an ISO standard that has been revised every three years since C++11: C++14, C++17, C++20 and C++23. Compilers such as GCC, Clang and Microsoft Visual C++ implement it. This course targets C++20 and points out when a feature is newer than that.

Two things C++ does not do for you are worth knowing on day one. It has no garbage collector: objects are destroyed at well-defined points, usually when they go out of scope, and standard library types clean up after themselves. And it trusts you: reading past the end of an array or using an object that no longer exists is undefined behavior, which may print something plausible today and crash tomorrow. Compiler warnings and the habits in this course are your safety net. The good news is that modern tools such as std::string, std::vector and smart pointers keep most of these traps out of your path when you use them by default.

Mental model: your first week with C++
  1. Write source in a .cpp file
  2. Compile with g++ -std=c++20
  3. Fix the first error, then recompile
  4. Run it and compare with your guess

Every lesson repeats this loop; what changes is how much the program does.

General pattern: the skeleton of every program

cpp
#include <library>    // pull in the library code you need

int main() {
    // statements run from top to bottom
    statement;
    return 0;         // 0 tells the system: success
}

Every program in this course starts from this skeleton. #include lines pull in library code, main() is where execution begins, and each statement inside the braces ends with a semicolon. The next lessons fill in each part.

Example: a first program

This program welcomes you to the course and prints the lesson count. The total of 35 is not typed into the code: the program adds up the five chapter sizes itself. You do not need to understand every piece of syntax yet; each line comes back in a later lesson. Predict the output before you run it.

welcome.cpp
#include <iostream>
#include <string>

int main() {
    std::string course = "C++";
    int basic = 11;
    int intermediate = 4;
    int advanced = 15;
    int projects = 3;
    int exercises = 2;

    int total = basic + intermediate + advanced + projects + exercises;

    std::cout << "Welcome to " << course << "!\n";
    std::cout << "Chapters: 5\n";
    std::cout << "Lessons: " << total << '\n';
    std::cout << "First stop: What is C++?\n";
    return 0;
}

Code breakdown

  1. Line 1#include <iostream>

    Pulls in the iostream header from the standard library, which provides std::cout for writing to the console.

  2. Line 5std::string course = "C++";

    A variable that holds text. std::string comes from the <string> header and manages its own memory, however long the text is.

  3. Line 12int total = basic + intermediate + advanced + projects + exercises;

    Adds the five int variables and stores the result, 35, in total. If a chapter gains a lesson, only that one number has to change.

  4. Line 14std::cout << "Welcome to " << course << "!\n";

    << sends pieces to the output one after another: text, a variable's value, more text. \n is the newline character that ends the line.

  5. Line 18return 0;

    Ends main and tells the operating system that the program finished successfully.

You should see
Welcome to C++!
Chapters: 5
Lessons: 35
First stop: What is C++?

How this course is organized

ChapterLessonsWhat you learn
Basic1-11Setup, program structure, variables, data types, operators, strings, if/else, switch and loops
Intermediate12-15Functions, arrays, pointers and references
Advanced16-30RAII and smart pointers, move semantics, classes and OOP, exceptions, files, std::vector, templates and concepts, algorithms and lambdas, std::jthread and a mini project
Projects31-33A Student Manager program built step by step in three parts
Exercises34-35Two practice sets: a basics warm-up and an OOP and STL challenge

The Basic chapter is the longest and the foundation for everything else. Intermediate is where you first handle memory directly, and the Advanced chapter opens by showing how smart pointers and RAII wrap those Intermediate pointers safely. The Projects chapter then asks you to combine everything from the earlier lessons in one program.

How to study each lesson

1. Predict before you run

For every example, write down what you expect the program to print. A wrong guess tells you exactly which part to reread.

2. Type the code yourself

Typing trains your fingers on the semicolons, braces and quotes that C++ insists on.

3. Break it on purpose

Delete a semicolon or misspell std::cout, then read the compiler's message. Errors you have caused deliberately are far less scary when they appear for real.

4. Compile with warnings on

When you compile on your own machine, use g++ -std=c++20 -Wall -Wextra. The Setup lesson shows how to install and run it.

In real projects

How this course connects to real work

C++ is the main language of game engines such as Unreal Engine, browser engines such as Chromium, compiler toolchains such as LLVM, and machine learning libraries such as the core of PyTorch. Open any of these large projects and the topics of this course appear everywhere: classes, std::vector and std::string, smart pointers that express who owns what, and templates that reuse one algorithm across many types.

Teams keep their C++ under control with rules. The C++ Core Guidelines, edited by Bjarne Stroustrup and Herb Sutter, collect many of those rules, and the defaults in this course follow them: initialize every variable, prefer library types to manual memory management, and treat warnings as errors. The final Student Manager project is written the same way, so it is the kind of code that could pass a review at work.

Common mistakes

Common mistakes when starting C++

1. Learning from outdated material without noticing

Old tutorials often write #include <iostream.h>. That header predates the first standard, so GCC 16 stops with "fatal error: iostream.h: No such file or directory". void main() is not valid C++ either: GCC answers "'::main' must return 'int'". When you see lines like these, treat the whole source with suspicion.

2. Taking a correct output as proof

In C++, a program with undefined behavior can pass a test today and fail with another compiler, another optimization level or another input. One correct output is not proof; warnings, edge cases and understanding why the code is right are.

3. Jumping ahead past the basics

It is tempting to go straight to templates or threads, but those lessons assume you already know types, scope, references and object lifetime. Reading an Advanced lesson without that foundation turns every error message into a long, unreadable puzzle.

Mini challenge

Mini challenge: your study card

Write a program that prints a study card for this course. The numbers must be calculated by the program.

  • Store your name in a std::string and your weekly pace in an int
  • Compute the total of 35 from the five chapter sizes (11, 4, 15, 3, 2)
  • Compute how many weeks the course takes at your pace (use int division)
  • Compute the number of the first Intermediate lesson from the Basic chapter's size
study_card.cpp
#include <iostream>
#include <string>

int main() {
    // TODO: your name (std::string) and lessons per week (int)

    // TODO: the Basic chapter size in its own variable,
    //       then the total of all five chapters

    // TODO: weeks needed = total / lessons per week
    // TODO: first Intermediate lesson = Basic size + 1

    // TODO: print four lines: name, lessons and pace, weeks, Intermediate start
    return 0;
}

Expected: With the name Aye and 5 lessons per week: Study card for Aye Lessons: 35, pace: 5 per week Weeks needed: 7 Intermediate starts at lesson 12

Show hint

Dividing an int by an int drops the remainder: 35 / 5 is 7 and 35 / 4 is 8. A line like std::cout << "Weeks: " << weeks << '\n'; prints text and a value together.

Show solution
study_card.cpp
#include <iostream>
#include <string>

int main() {
    std::string learner = "Aye";
    int perWeek = 5;

    int basicLessons = 11;
    int allLessons = basicLessons + 4 + 15 + 3 + 2;
    int weeks = allLessons / perWeek;
    int firstIntermediate = basicLessons + 1;

    std::cout << "Study card for " << learner << '\n';
    std::cout << "Lessons: " << allLessons << ", pace: " << perWeek << " per week\n";
    std::cout << "Weeks needed: " << weeks << '\n';
    std::cout << "Intermediate starts at lesson " << firstIntermediate << '\n';
    return 0;
}

Quick quiz 1 / 3

Which step turns a .cpp file into a program the operating system can run?

Quick quiz 2 / 3

What does int a = 11; int b = 4; std::cout << "Lessons: " << a + b << '\n'; print?

Quick quiz 3 / 3

Which of these does C++ NOT do for you automatically?

What to remember

  • C++ is a compiled, statically typed language that pairs C's speed with zero-overhead abstractions.
  • Every program has #include lines, a main() function and statements that end with semicolons.
  • The course has five chapters and 35 lessons, from Basic through Advanced to a Student Manager project and two exercise sets.
  • Predict, type, break things on purpose, and compile with -std=c++20 -Wall -Wextra.

The Current ISO C++ Standard (C++23) — Standard C++ Foundation

Updated on

Progress is saved only in this browser on this device. It isn't synced to other devices.

Report a problem with this lessonOpens your email app with this lesson's address filled in — nothing is sent until you send it.

C++ Home: Start Here | Thuta Learning