Games like Counter-Strike, browsers like Chrome and Firefox, databases like MySQL, the trading engines of stock exchanges, and the compilers that build other programs: a huge amount of the software you use every day is written in C++. It is also one of the most common languages for coding rounds in placements and for competitive programming.
Before we write any code, let's understand what C++ is, where it came from, why it is still so popular more than 40 years after it was created, and what makes it different from C and Java.
What is C++?
C++ is a general-purpose, compiled, statically typed programming language that gives you the low-level control of C together with high-level features such as classes, templates and a large standard library.
Let's break that definition into small pieces:
General-purpose: it is not limited to one kind of task. You can write games, operating system components, desktop apps, servers or embedded software in it.
Compiled: your source code is translated once by a compiler into machine code for your processor. The result runs directly on the hardware, without an interpreter or a virtual machine in between. This is a big reason C++ is fast.
Statically typed: the type of every variable (
int,double,std::string...) is known at compile time. Many mistakes are therefore caught before the program ever runs.Low-level control: like C, you can work with memory addresses (pointers), decide exactly how data is laid out in memory, and decide when memory is allocated and freed.
High-level features: unlike C, you also get classes and objects, templates (generic code), exceptions, lambdas and the Standard Template Library (STL) with ready-made containers like
vector,mapand algorithms likesort.
Here is the smallest useful C++ program. Don't worry about the details yet; the next chapter, Your First C++ Program, explains every line.
#include <iostream>
int main() {
std::cout << "Hello, C++!\n";
return 0;
}
Output:
Hello, C++!
A Short History
C++ was created by the Danish computer scientist Bjarne Stroustrup at AT&T Bell Labs (the same place where C and Unix were born).
1979: Stroustrup starts working on "C with Classes". He wanted the speed and closeness to hardware of C, but also the way of organising large programs into classes that he had seen in the language Simula.
1983: the language is renamed C++. The name is a programmer's joke:
++is the increment operator in C, so "C++" means "one step beyond C".1985: the first commercial release, together with Stroustrup's book The C++ Programming Language.
1998: the first international standard, C++98, is published by ISO.
Since then, C++ has been developed by an ISO committee (called WG21) made of people from companies, universities and compiler teams around the world. No single company owns C++.
C++ Standards: C++98 to C++26
A standard is the official document that says exactly what is valid C++ and what each feature means. Compiler makers (GCC, Clang, Microsoft) implement the standard. Since C++11, a new standard comes out every three years.
| Standard | Year | Some important additions |
|---|---|---|
| C++98 | 1998 | First ISO standard: classes, templates, exceptions, the STL |
| C++03 | 2003 | Mostly bug fixes to C++98 |
| C++11 | 2011 | The "modern C++" revolution: auto, range-based for, lambdas, move semantics, smart pointers, nullptr, threads |
| C++14 | 2014 | Smaller improvements: binary literals, digit separators, generic lambdas, std::make_unique |
| C++17 | 2017 | Structured bindings, std::optional, std::variant, std::string_view, std::filesystem, if constexpr |
| C++20 | 2020 | Concepts, ranges, coroutines, modules, std::format, the <=> operator |
| C++23 | 2023 (published by ISO in 2024) | std::print and std::println, std::expected, import std;, "deducing this", std::flat_map |
| C++26 | 2026 | Static reflection, contracts, std::execution. The committee finished the technical work in March 2026; the formal ISO publication step comes after that. |
In this tutorial we write modern C++ and compile everything as C++23, the latest published standard. Whenever a feature needs a particular standard, the chapter says so (for example, "C++11" or "C++20").
You can ask the compiler which standard it is using through the predefined macro __cplusplus:
#include <iostream>
int main() {
std::cout << "__cplusplus = " << __cplusplus << '\n';
if (__cplusplus >= 202302L)
std::cout << "Compiled as C++23 (or newer)\n";
else if (__cplusplus >= 202002L)
std::cout << "Compiled as C++20\n";
else if (__cplusplus >= 201703L)
std::cout << "Compiled as C++17\n";
else
std::cout << "Older than C++17\n";
}
Output with g++ -std=c++23:
__cplusplus = 202302
Compiled as C++23 (or newer)
The same program built with -std=c++17 prints 201703, and with -std=c++20 prints 202002. (The value is a long constant like 202302L; the L suffix is not printed.) Note that GCC 16 and later use C++20 by default and older GCC versions use C++17, so it is a good habit to always pass the -std= option yourself.
Why Learn C++?
1. Speed and control
C++ follows the zero-overhead principle, which Stroustrup describes in two parts:
What you don't use, you don't pay for. And what you do use, you couldn't hand-code any better.
For example, a std::vector<int> is about as fast as a carefully hand-written dynamic array in C, but much safer and easier to use. This is why C++ is chosen when performance really matters: game engines, browsers, databases, high-frequency trading, embedded systems and machine-learning libraries (the fast core of libraries like PyTorch and TensorFlow is written in C++).
2. Placements and competitive programming
Most competitive programmers use C++ because it is fast and the STL gives ready-made data structures (vector, set, map, priority_queue) and algorithms (sort, lower_bound). Online judges usually have tight time limits, and C++ code comfortably fits inside them. Interviewers at product companies also love C++ questions about pointers, virtual functions, memory and the STL.
3. It teaches you how computers really work
In Java or Python, memory is managed for you. In C++ you see the stack and the heap, object lifetimes, copying versus moving, and the cost of each operation. Once you understand these, every other language becomes easier to understand.
4. It is multi-paradigm
C++ does not force one style. You can write:
Procedural code (functions and data, like C)
Object-oriented code (classes, inheritance, polymorphism)
Generic code (templates that work with any type)
Functional-style code (lambdas, algorithms, ranges)
Here is a small taste that mixes a class, an STL container, an algorithm and a lambda. You will understand every piece of it by the end of this tutorial:
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
class Student {
public:
std::string name;
int marks;
};
int main() {
std::vector<Student> students = {
{"Aman", 78}, {"Priya", 92}, {"Rahul", 85}
};
// sort by marks, highest first
std::sort(students.begin(), students.end(),
[](const Student& a, const Student& b) { return a.marks > b.marks; });
for (const Student& s : students)
std::cout << s.name << " : " << s.marks << '\n';
}
Output:
Priya : 92
Rahul : 85
Aman : 78
How a C++ Program Runs
C++ is a compiled language. The journey from your source file to a running program looks like this:
hello.cpp (your source code, plain text)
│
▼ compiler (g++, clang++, MSVC)
hello.o / hello.obj (object file: machine code)
│
▼ linker (joins your code with the library code)
hello / hello.exe (executable file)
│
▼ operating system loads and runs it
Output on the screen
Compare this with Java, where the compiler produces bytecode and the JVM runs it, or Python, where an interpreter reads your program while it runs. A C++ executable is native machine code for one platform: an .exe built on Windows does not run on Linux, but the source code can be recompiled for each platform. The chapter C++ Program Structure explains each step of this pipeline in detail.
The three most popular C++ compilers are:
| Compiler | Command | Mainly used on |
|---|---|---|
| GCC (GNU Compiler Collection) | g++ | Linux, Windows (through MinGW-w64 / MSYS2 or WSL) |
| Clang (LLVM) | clang++ | macOS (the default with Xcode), Linux, Windows |
| Microsoft Visual C++ (MSVC) | cl | Windows, through Visual Studio |
All programs in this tutorial were compiled with g++ 15 using -std=c++23 -Wall -Wextra, and the outputs shown are the real outputs.
C vs C++ vs Java
Many students learn C first and Java later, so this comparison is very useful (and very common in viva and interviews):
| Point | C | C++ | Java |
|---|---|---|---|
| Paradigm | Procedural | Multi-paradigm (procedural, OOP, generic, functional) | Mainly object-oriented |
| Classes and objects | No (only struct with data) | Yes | Yes (everything lives inside a class) |
| How it runs | Compiled to machine code | Compiled to machine code | Compiled to bytecode, run by the JVM |
| Memory management | Manual (malloc/free) | Manual (new/delete) or automatic through RAII and smart pointers | Automatic garbage collection |
| Pointers | Yes | Yes, plus references | No direct pointers (only references to objects) |
| Multiple inheritance of classes | Not applicable | Yes | No (only through interfaces) |
| Operator overloading | No | Yes | No |
| Generic programming | No (only macros or void*) | Templates | Generics (type erasure) |
| Standard library | Small | Large (STL, strings, streams, threads, ...) | Very large |
| Exception handling | No | Yes | Yes (plus checked exceptions) |
Is C++ a superset of C?
Almost, but not exactly. Most C code compiles as C++, which is why you can call C library functions like printf from C++. But there are real differences. A few examples:
In C,
int *p = malloc(4);is fine. In C++, convertingvoid*toint*needs an explicit cast.In C, a character literal like
'A'has typeint, sosizeof('A')is usually 4. In C++ it has typechar, sosizeof('A')is 1.Words like
class,new,deleteandtemplateare keywords in C++, so a C program that uses them as variable names will not compile as C++.Variable-length arrays (
int a[n];with a runtimen) are part of C99 but are not standard C++. GCC accepts them as an extension, but you should usestd::vectorinstead.
So the better statement is: C++ is based on C and is largely compatible with it.
Where is C++ Used?
| Area | Examples |
|---|---|
| Game development | Unreal Engine, most AAA game engines |
| Web browsers | Chrome (Chromium), Firefox (alongside Rust), Safari (WebKit) |
| Databases | MySQL, MongoDB, ClickHouse |
| Operating systems and tools | Parts of Windows, macOS and Android; compilers such as GCC and Clang |
| Finance | Low-latency trading systems |
| Machine learning | The fast core of PyTorch, TensorFlow and ONNX Runtime |
| Embedded and automotive | Car control units, robotics, IoT devices |
| Desktop applications | Adobe Photoshop, Microsoft Office, many Qt applications |
What Will You Learn in This Tutorial?
Basics: program structure, variables and data types, constants and literals, input and output, operators, type conversion.
Control flow:
if,switch, loops,breakandcontinue.Functions: overloading, default arguments, inline functions and recursion.
Memory: arrays, strings, pointers, references and dynamic memory.
Object-oriented programming: classes, constructors and destructors,
this, static members, friends, operator overloading, inheritance, polymorphism and abstract classes.Generic programming and the STL: templates, containers, algorithms, iterators and lambdas.
Modern C++: smart pointers, move semantics, and the features added from C++11 to C++23.
Practical C++: exceptions, file handling, namespaces and C++ for competitive programming.
Common Misconceptions
"C++ is just C with classes." That was true in 1979. Modern C++ has templates, the STL, lambdas, smart pointers, move semantics, concepts, ranges and much more. Good modern C++ code looks very different from C code.
"C++ is old and dying." C++ gets a new standard every three years and is consistently among the most used languages in the world.
"In C++ you must always manage memory by hand." Modern C++ rarely uses raw
newanddelete. Containers likestd::vectorand smart pointers likestd::unique_ptrfree memory automatically when it is no longer needed."A C++ program compiled once runs everywhere." No. The executable is machine code for one operating system and processor. The source code is portable; you recompile it for each platform.
Interview / Exam Questions
Who developed C++, and what was it originally called?
Bjarne Stroustrup at AT&T Bell Labs, starting in 1979. It was originally called "C with Classes" and was renamed C++ in 1983.
Why is it called C++?
++ is the increment operator, so the name suggests "the next step after C" or "C incremented by one".
Is C++ a compiled or interpreted language?
Compiled. The compiler translates source code into native machine code, and a linker produces an executable that the operating system runs directly.
Is C++ a purely object-oriented language?
No. C++ is multi-paradigm. You can write a complete program without a single class (for example, only main and some functions). Also, built-in types like int are not objects of a class, and functions can exist outside classes. Java is much closer to "everything is in a class".
What is the latest C++ standard?
C++23 is the latest published ISO standard (ISO/IEC 14882:2024). The committee completed the technical work on C++26 in March 2026, and C++29 is the next one being worked on.
What is sizeof('A') in C and in C++?
In C, 'A' has type int, so the result is sizeof(int) (usually 4). In C++, 'A' has type char, so the result is always 1.
What does the zero-overhead principle mean?
A feature you don't use adds no cost to your program, and a feature you do use is as efficient as anything you could reasonably write by hand.
In Simple Words
C++ is C plus powerful high-level features. It is compiled to fast machine code, gives you full control over memory, and still lets you write clean, reusable code with classes, templates and the STL.
Remember the key points:
Creator → Bjarne Stroustrup, Bell Labs (1979, renamed C++ in 1983)
Type → compiled, statically typed, multi-paradigm
Standards → C++98, 03, 11, 14, 17, 20, 23 (latest published), 26
Strengths → speed, control over memory, STL, zero-overhead abstractions
Used in → games, browsers, databases, trading, ML libraries, embedded
In the next chapter, Your First C++ Program, we will write, compile and run our first program and understand each line of it.