C++ Introduction
C++ is a general-purpose, compiled programming language created by Bjarne Stroustrup at Bell Labs, starting in 1979. It began life as "C with Classes": the speed and hardware access of C, plus tools for organising large programs. Today C++ is an international standard (ISO) that is updated every three years — C++11, C++14, C++17, C++20, C++23 — and every new version makes the language safer and more pleasant to use.
What is C++ used for?
C++ shines wherever performance and control matter:
- Game engines (Unreal Engine) and graphics software
- Web browsers (Chrome, Firefox) and their JavaScript engines
- Databases, trading systems and other low-latency servers
- Operating systems, drivers and embedded devices
- Scientific computing, simulations and machine-learning libraries
Why learn C++?
| Feature | What it means for you |
|---|---|
| Compiled to machine code | Programs run very fast and use little memory |
| Zero-cost abstractions | Classes, templates and lambdas add no runtime overhead you did not ask for |
| Huge standard library (STL) | Ready-made containers (vector, map) and algorithms (sort, find) |
| Runs everywhere | From microcontrollers to supercomputers |
| Close to C | Knowing C++ makes C, C#, Java and Rust much easier to pick up |
C++ vs C
C++ is (almost) a superset of C, so most C code also compiles as C++. The big additions are classes and objects, templates (generic code), exceptions, references, a much richer standard library, and modern features such as auto, lambdas and smart pointers. In this course you will write modern C++ — the style used in new projects today.
Your first C++ program
Every C++ program starts running in a function called main. Press ▶ Run to compile and run it, then change the text and run it again.
#include <iostream>
int main() {
std::cout << "Hello, World!\n";
return 0;
}Hello, World!
Line by line:
#include <iostream>pulls in the input/output part of the standard library.int main()is the entry point. It returns anintto the operating system;0means "success".std::cout << "..."sends text to the console.\nstarts a new line.
Tip: In every playground on ExcelTAD you can edit the code and press Ctrl+Enter to run it.
Printing several lines
Each statement ends with a semicolon, and statements run from top to bottom:
#include <iostream>
int main() {
std::cout << "C++ is fast.\n";
std::cout << "C++ is powerful.\n";
std::cout << "C++ is everywhere!\n";
}C++ is fast.
C++ is powerful.
C++ is everywhere!
Note:
mainis the only function where you may leave outreturn 0;— the compiler adds it for you.
How C++ code becomes a program
C++ source code is not run directly. A compiler (such as g++, clang++ or MSVC) translates your .cpp file into a native executable, which you then run. The examples on this site are compiled with g++ in C++20 mode on a remote server, so the first run may take a second or two.
Test yourself
Who created C++?
- Dennis Ritchie
- Bjarne Stroustrup
- James Gosling
- Guido van Rossum
Which header lets you use std::cout?
- <stdio>
- <string>
- <iostream>
- <console>
What does return 0; from main usually mean?
- The program crashed
- The program finished successfully
- Restart the program
- Nothing at all