C++
- Pronunciation
- SEE-PLUS-PLUS
In short
C++ is a compiled, statically typed language that extends C with classes and templates while keeping low-level control over memory and performance.
What is C++?
C++ is a general-purpose programming language created by Bjarne Stroustrup at Bell Labs, starting in 1979 as "C with Classes" and renamed C++ in 1983. The name is a programmer's joke: ++ is the C operator that increases a value by one. It is standardized by ISO, with a new version about every three years, such as C++17, C++20, and C++23.
C++ is statically typed and compiles to native machine code. It supports several styles: procedural code like C, object-oriented code with classes and inheritance, and generic code with templates, which generate type-specific versions of functions and classes at compile time. There is no garbage collector; instead, modern C++ relies on RAII (Resource Acquisition Is Initialization), where an object releases its memory or other resources automatically in its destructor when it goes out of scope. Smart pointers such as std::unique_ptr and std::shared_ptr apply this idea to heap memory, so hand-written new and delete are rarely needed.
C++ is common in game engines, web browsers, databases, trading systems, embedded devices, and the performance-critical cores of machine learning libraries. Its guiding principle of "zero-overhead abstractions" means you shouldn't pay a runtime cost for features you don't use. Working in C++ is like having a fully equipped professional workshop: it can build almost anything, but it takes time to learn which tools are safe to use and when.
C++ is no longer just "C with extras." Although it can compile most C code, idiomatic modern C++ looks quite different, using standard containers like std::vector and std::string instead of raw arrays and manual memory management. It is also unrelated to C# beyond the name: C# is a separate language that runs on a managed runtime with a garbage collector.
Key takeaways
- C++ compiles to native machine code and offers fine-grained control over performance.
- It supports procedural, object-oriented, and generic programming styles.
- Memory is managed through scope-based RAII and smart pointers rather than a garbage collector.
- It is common in game engines, browsers, databases, and other performance-critical software.
Example
#include <iostream>
#include <string>
#include <vector>
int main() {
// std::vector frees its own memory: no manual delete needed
std::vector<std::string> names = {"Ada", "Grace", "Alan"};
names.push_back("Barbara");
for (const auto& name : names) {
std::cout << "Hello, " << name << "\n";
}
return 0;
}Readers ask
Is C++ harder to learn than other languages?
C++ is generally considered one of the more complex languages because it is large and gives you direct control over memory. Many learners start with a smaller subset of modern C++, using standard containers and smart pointers, and grow from there.
What is the difference between C++ and C#?
They are separate languages. C++ compiles to native code and manages memory without a garbage collector, while C# runs on the .NET runtime with automatic garbage collection.
What does RAII mean in C++?
RAII (Resource Acquisition Is Initialization) means tying a resource, such as memory, a file, or a lock, to an object's lifetime. The resource is released automatically in the object's destructor when the object goes out of scope.
Often compared
See also
- CProgramming Languages, p. 3C is a compiled, low-level programming language that gives direct control over memory and is used to build operating systems, drivers, and embedded software.
- C#Programming Languages, p. 4C# is a statically typed, object-oriented language that runs on the .NET runtime with garbage collection and is used for web backends, desktop apps, and games.
- OOPProgramming Fundamentals, p. 40OOP, or object-oriented programming, is a way of structuring code around objects that bundle related data together with the functions that act on that data.
- GenericsProgramming Fundamentals, p. 24Generics are a language feature that lets you write functions, classes, and types that work with many data types while still keeping full type safety.
- CompilerProgramming Fundamentals, p. 11A compiler is a program that translates source code written in a programming language into a lower-level form, such as machine code, that a computer can run.
- Memory LeakOperating Systems, p. 19A memory leak is a bug where a program keeps holding memory it no longer needs, so its memory usage grows over time and can slow down or crash the system.
Spotted a mistake or something missing on this page?Suggest an edit