Example 1 — Hello, World!
#include <iostream>
int main() {
std::cout << "Hello, World!" << std::endl;
return 0;
} The iostream library provides console I/O. This program is the traditional first step in C++.

This page is a self-contained introduction to C++—no prior object-oriented experience required (though basic C helps). You will understand what C++ is, write your first program, and learn how source code becomes a running application.
C + OOP power.
Stroustrup era.
iostream demo.
g++ workflow.
Edit to execute.
Core concepts.
C++ is a general-purpose, high-level language developed in the early 1980s. It extends the C programming language with object-oriented features such as classes, inheritance, and polymorphism.
C++ is known for performance, efficiency, and flexibility. It powers operating systems, game engines (Unreal), web browsers (Chrome rendering), embedded firmware, and financial trading systems. It is a compiled language: source must be built into machine code before execution.
Learn console I/O and control flow first. Add classes and the STL (std::vector, std::string) before templates and manual memory management.
Bjarne Stroustrup is known as the father of C++. The Danish computer scientist began developing “C with Classes” at Bell Labs in 1979; the name C++ (C incremented) appeared in 1983. His goal was a language as efficient as C but better suited to large software projects.
| Milestone | Year | Notes |
|---|---|---|
| C with Classes | 1979 | Bjarne Stroustrup, Bell Labs |
| Name “C++” | 1983 | ++ means increment in C |
| First commercial release | 1985 | C++ 1.0 |
| ANSI/ISO standardization | 1998 | C++98 |
| Major updates | 2011 | C++11 (auto, smart pointers, move) |
| 2017 | C++17 (structured bindings, filesystem) | |
| 2020 | C++20 (concepts, ranges, coroutines) |
C++ code is written in a text editor or IDE (Visual Studio, VS Code, CLion, Code::Blocks). After you save a .cpp file, a compiler such as GCC or Clang translates it to machine code. The linker combines your object file with libraries; the OS then runs the executable.
Unlike interpreted languages, compile-time checks catch many type errors before the program ever runs.
Yes, in practice. Popular compilers (GCC, Clang, MSVC toolchain components) and libraries are open source or freely available. The C++ standard is maintained by ISO; implementations follow the standard and are widely distributed without licensing fees for development.
Thousands of open-source C++ libraries exist for graphics, networking, machine learning, and more.
A minimal C++ console program includes the iostream header, a main function, and output via std::cout:
#include <iostream>
int main() {
std::cout << "Hello, World!" << std::endl;
return 0;
} #include <iostream> — header for console input/output.std::cout — standard character output stream.<< — stream insertion operator; chains output left to right.std::endl — newline and flush the buffer.int main() — program entry point; returns an exit code to the OS.std:: is the standard library namespace (or using namespace std; in small learning programs).g++ demo.cpp -std=c++17 -Wall -o demo
./demo /* Linux / macOS */
demo.exe /* Windows */ -std=c++17 — enable a modern C++ standard (C++11/14/17/20 also common).-Wall — show useful warnings; fix them while learning.g++ vs gcc — use g++ for .cpp files so the linker pulls C++ runtime libraries automatically.| Concept | What it does |
|---|---|
| Variables & types | int, double, char, bool |
| Control flow | if, else, switch, loops |
| Functions | Reusable logic; overloading allowed |
| Classes & OOP | Encapsulation, inheritance, polymorphism |
| STL | vector, string, map, algorithms |
| References & pointers | Direct memory access (use carefully) |
| Templates | Generic programming (vector<T>) |
| RAII | Resources tied to object lifetime (smart pointers) |
| Task | Example |
|---|---|
| Output | std::cout << "Hi\n"; |
| Input | std::cin >> n; |
| String | std::string name = "Alex"; |
| Vector | std::vector<int> v = {1, 2, 3}; |
| Condition | if (x > 0) { ... } |
| for loop | for (int i = 0; i < n; i++) { ... } |
Five starter programs. Save each as a .cpp file and compile with g++.
#include <iostream>
int main() {
std::cout << "Hello, World!" << std::endl;
return 0;
} The iostream library provides console I/O. This program is the traditional first step in C++.
#include <iostream>
int main() {
int age = 20;
double gpa = 3.85;
char grade = 'A';
std::cout << "Age: " << age << "\n";
std::cout << "GPA: " << gpa << "\n";
std::cout << "Grade: " << grade << "\n";
return 0;
} #include <iostream>
int main() {
int num;
std::cout << "Enter a number: ";
std::cin >> num;
std::cout << "You entered: " << num << "\n";
return 0;
} #include <iostream>
int add(int a, int b) {
return a + b;
}
int main() {
std::cout << "Sum = " << add(3, 5) << "\n";
return 0;
} #include <iostream>
int main() {
int n;
std::cout << "Enter n: ";
std::cin >> n;
if (n % 2 == 0)
std::cout << n << " is even\n";
else
std::cout << n << " is odd\n";
return 0;
} | Language | Style | Best for beginners when… |
|---|---|---|
| C++ | Multi-paradigm, compiled | You want performance plus OOP and already know some C |
| C | Procedural, compiled | You want minimal syntax and systems-level basics first |
| C# | OOP, managed .NET | You prefer garbage collection and rapid app development |
| Python | High-level, interpreted | You want the fastest path to scripts and prototyping |
Headers, functions, classes, and main in your editor or IDE.
g++ preprocesses, parses templates, and emits object code.
The linker resolves symbols and builds the final executable.
main runs; std::cout prints to the console.
#include <iostream>, std::cout, and int main() to start.g++ file.cpp -std=c++17 -Wall -o out.-Wall and treat warnings seriouslystd::string and std::vector over raw arrays when learningif and loop bodynew/deleteusing namespace std; in large header files (OK in tiny learning snippets)printf and C++ streams without reasonThe ++ in C++ is the increment operator from C—the language is literally “C plus one step forward.” Some developers joke that C++ also means “more to learn,” but that depth is what makes it powerful for performance-critical software once you build fundamentals on this page.
Copy any example into the online compiler or compile locally with g++.
11 people found this page helpful