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.
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:
#include <iostream>
int main() {
std::cout << "Hello, C++!\n";
return 0;
}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:
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.
- You write source code in a file such as
hello.cpp. - The compiler (for example
g++,clang++or Microsoft'scl) checks it and translates it into machine code. - You run the resulting program (
hello.exeon Windows,./helloon macOS and Linux).
g++ hello.cpp -o hello
./helloBecause 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++ 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#
- Fundamentals: variables, types, operators and input.
- Control flow:
if,switchand loops. - Functions: parameters, references, overloading and recursion.
- Arrays, strings and vectors: storing collections and text.
- References, pointers and memory, including smart pointers.
- Object-oriented programming: classes, inheritance and virtual functions.
- The Standard Template Library:
map,set,unordered_mapand algorithms. - 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?