A compiled, statically typed, multi-paradigm language that gives you C-level control of memory with high-level abstractions that cost nothing at run time.
Why C++?
C vs C++
| Feature | C | C++ |
|---|---|---|
| Paradigm | Procedural | Procedural + OOP + generic + functional |
| Structs | Data only | class/struct with methods, access control, inheritance |
| Memory | malloc / free | new / delete, but prefer containers & smart pointers |
| Strings | char* + <string.h> | std::string, std::string_view |
| Pass by | Value or pointer | Value, pointer or reference (int&) |
| Overloading | No | Function & operator overloading |
| Generic code | Macros / void* | Templates, concepts |
| Errors | Return codes, errno | Exceptions (plus return codes, std::optional) |
| Namespaces | No (one global scope) | namespace |
| Standard library | Small (stdio, stdlib…) | STL: containers, algorithms, threads, chrono, … |
Your first program
#include <iostream>
int main() {
std::cout << "Hello, C++!\n";
int year = 2020;
std::cout << "Standard: C++" << year % 100 << '\n';
return 0; // optional in main: falling off the end returns 0
}Hello, C++!
Standard: C++20The standards
| Standard | Headline features |
|---|---|
| C++98/03 | STL, templates, exceptions, std::string |
| C++11 | The “modern C++” reset: auto, lambdas, move semantics, nullptr, smart pointers, range-for, constexpr, threads |
| C++14 | Generic lambdas, make_unique, relaxed constexpr |
| C++17 | Structured bindings, optional/variant/any, string_view, if constexpr, filesystem |
| C++20 | Concepts, ranges, coroutines, modules, <=>, std::format, std::span |
| C++23 | std::print, std::expected, ranges::to, deducing this |
Is C++ an object-oriented language?
Why is C++ faster than Java or Python?