Skip to content

Module 1 · Getting Started with C++ — topic 1 of 3

Introduction to C++

C++ is a compiled, multi-paradigm language that adds classes, templates, exceptions and a rich standard library to C while keeping C's performance and control over memory.

Beginner 12 min read·Lesson 1 of 40 in C++ Programming

Learning objectives

  • Describe where C++ came from and how it extends C
  • Name the paradigms C++ supports
  • Compile and run a first C++ program

Definition

C++ is a statically typed, compiled, general-purpose programming language standardised by ISO (C++98, 11, 14, 17, 20, 23) that supports procedural, object-oriented and generic programming with zero-overhead abstractions.

Introduction

Bjarne Stroustrup began C++ in 1979 as “C with Classes” at Bell Labs. He wanted the efficiency of C together with the program-organisation ideas of Simula, one of the first object-oriented languages. The language was renamed C++ in 1983 — ++ being C's increment operator.

Today C++ powers game engines (Unreal), browsers (Chrome's rendering engine), databases (MySQL, MongoDB), trading systems, compilers (LLVM) and much of the software inside cars and aircraft.

Why it matters

C++ lets you write high-level, reusable code — classes, templates, containers — without paying a run-time cost for features you don't use. That combination is why performance-critical industries still choose it.

Learning C++ also teaches object-oriented design and generic programming, ideas that transfer directly to Java, C# and Python, and it is the most popular language for competitive programming thanks to its fast Standard Template Library (STL).

Detailed explanation

C++ is compiled like C: g++ or clang++ translates .cpp files to native machine code. Almost every valid C program is also valid C++, but C++ is a separate language with stricter type rules.

C++ supports several paradigms: procedural (functions), object-oriented (classes, inheritance, virtual functions), generic (templates) and, since C++11, a functional style (lambdas).

The zero-overhead principle: what you don't use, you don't pay for; and what you do use, you couldn't hand-code any better. A std::vector is as fast as a carefully managed C array, but safer.

StandardHighlights
C++98/03First ISO standard; STL containers and algorithms
C++11auto, lambdas, smart pointers, move semantics, range-for
C++14Generic lambdas, make_unique
C++17Structured bindings, optional, variant, string_view, filesystem
C++20Concepts, ranges, modules, coroutines
C++23std::print, expected, more ranges

Syntax

C++
#include <iostream>
int main() {
std::cout << "text" << '\n';
return 0;
}
  • <iostream> provides the standard input/output streams.
  • std::cout is the standard output stream; << inserts values into it.
  • std:: is the namespace of the standard library.
  • In C++, int main() with empty parentheses means no parameters.

Code examples

Hello, C++

C++
#include <iostream>
int main() {
std::cout << "Hello, C++!\n";
return 0;
}
Output
Hello, C++!

Chaining output

C++
#include <iostream>
int main() {
int year = 1983;
std::cout << "C++ got its name in " << year << ".\n";
return 0;
}
Output
C++ got its name in 1983.

Each << sends one value to the stream; types are handled automatically, with no format specifiers.

More examples

A taste of the standard library

C++
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
int main() {
std::vector<std::string> langs = {"Python", "C", "Java", "C++"};
std::sort(langs.begin(), langs.end());
for (const std::string& name : langs)
std::cout << name << ' ';
std::cout << "\n" << langs.size() << " languages\n";
return 0;
}
Output
C C++ Java Python 
4 languages

Step-by-step explanation

  • std::vector<std::string> is a growable array of strings that manages its own memory.
  • std::sort sorts any range given by two iterators; strings compare alphabetically.
  • The range-based for visits each element; const std::string& avoids copying it.
  • langs.size() returns the number of elements — no manual counting as in C.

Expected output

Running “A taste of the standard library” prints exactly:

TextOutput
C C++ Java Python
4 languages

Practical applications

  • Game engines such as Unreal Engine are written in C++.
  • Google Chrome, Firefox and most of Windows and macOS applications use C++.
  • High-frequency trading systems use C++ for microsecond latency.
  • Competitive programmers favour C++ for its fast STL.

Best practices

  • Compile with -std=c++17 -Wall -Wextra (or newer).
  • Prefer standard library types (std::string, std::vector) over raw C arrays and char buffers.
  • Write '\n' rather than std::endl unless you need to flush the stream.

Common mistakes

Forgetting the std:: prefix

Avoid

cout << "hi";

Prefer

std::cout << "hi";

Standard library names live in namespace std. Without the prefix (or a using-declaration) the name is not found.

Using C headers for C++ features

Avoid

#include <stdio.h>
std::cout << 1;

Prefer

#include <iostream>
std::cout << 1;

std::cout is declared in <iostream>, not <stdio.h>.

Important notes

  • This course targets C++17; features from C++20 are labelled where they appear.
  • C++ is not a strict superset of C: for example, int *p = malloc(4); compiles in C but needs a cast in C++.

Key takeaways

  • C++ adds classes, templates, exceptions and the STL to C.
  • Programs start in main; std::cout << value prints.
  • Modern C++ (C++11 and later) is much safer and more expressive than C-style C++.

Try it yourself

  1. 1
    Print your name and branch on separate lines using a single std::cout statement.
  2. 2
    Store three integers in a std::vector<int>, sort them and print them.

Finished reading? Mark it complete to update your dashboard.

Suggested practice

3 questions test this exact topic. Answers and explanations are revealed after you submit.

  • BeginnerWho created C++ and what was it first called?
  • BeginnerWhich paradigms does C++ support?
  • BeginnerWhat is printed?
Practise this topic