Skip to content
Laviyx Learn

Try

C++ course menu

Introduction to C++: What It Is, What It Is Used For, and How It Works

A beginner-friendly introduction to C++: what the language is, where it is used (games, browsers, finance, embedded systems), how compiling works, how C++ compares with C, Java and Python, and what you will learn in this course.

Beginner4 min readUpdated
On this page

C++ is a general-purpose programming language known for two things: speed and control. It turns your code into machine instructions that run directly on the processor, and it lets you decide exactly how memory is used. That combination is why much of the software that needs to be fast is written in C++.

A first look#

Here is a complete C++ program:

hello.cpp (C++)
#include <iostream>

int main() {
    std::cout << "Hello, C++!\n";
    return 0;
}
Output
Hello, C++!

Every C++ program starts running in a function called main. You will write and run this program yourself in First C++ Program.

Where C++ is used#

C++ runs underneath a huge amount of everyday software:

AreaExamples
Games and game enginesUnreal Engine, many console and PC games
Web browsersThe core of Chrome, Firefox and Edge
Operating systems and toolsParts of Windows, macOS, compilers, databases
FinanceTrading systems where microseconds matter
Embedded systemsCars, medical devices, robots, IoT devices
Scientific and AI computingSimulations, and the fast cores of libraries such as TensorFlow and PyTorch

When a Python library feels fast, there is often C or C++ doing the heavy work underneath.

How C++ code runs: compiling#

Python runs your code through an interpreter. C++ is a compiled language: a program called a compiler translates your source file into an executable file before it runs.

  1. You write source code in a file such as hello.cpp.
  2. The compiler (for example g++, clang++ or Microsoft's cl) checks it and translates it into machine code.
  3. You run the resulting program (hello.exe on Windows, ./hello on macOS and Linux).
Terminal
g++ hello.cpp -o hello
./hello

Because the translation happens up front, the compiler catches many mistakes, such as a misspelled name or the wrong type of value, before the program ever runs.

C++ compared with other languages#

C++CJavaPython
Runs asNative machine codeNative machine codeBytecode on the JVMInterpreted bytecode
SpeedVery fastVery fastFastSlower
MemoryYou control it (with safe helpers)Fully manualGarbage collectedGarbage collected
Object-orientedYesNoYesYes
Learning curveSteeperSteepModerateGentle

C++ started in 1979 as "C with Classes", created by Bjarne Stroustrup. It keeps almost all of C, and adds classes, templates, a large standard library and much more. Since 2011 the language has been updated every three years (C++11, 14, 17, 20, 23), and modern C++ is much safer and easier to write than older code you may see online.

Is C++ hard to learn?#

C++ is bigger than Python, and it asks you to think about things Python hides, such as types and memory. But you do not need all of it to be productive. This course introduces one idea at a time, uses modern C++ from the start, and avoids old habits that cause bugs.

Learning C++ also teaches you how computers really work: how values are stored, what a pointer is, and why some code is faster than other code. That knowledge makes you better in every language.

What you will learn#

  1. Fundamentals: variables, types, operators and input.
  2. Control flow: if, switch and loops.
  3. Functions: parameters, references, overloading and recursion.
  4. Arrays, strings and vectors: storing collections and text.
  5. References, pointers and memory, including smart pointers.
  6. Object-oriented programming: classes, inheritance and virtual functions.
  7. The Standard Template Library: map, set, unordered_map and algorithms.
  8. Advanced C++: lambdas, templates, exceptions, files, move semantics and threads.

Key takeaway#

Next, set up a compiler in Installing a C++ Compiler.

Finished this lesson?