CodeMIRAI
0 XP

Introduction to C++

2 min read 1 runnable example Quiz included

C++ was created by Bjarne Stroustrup in 1985 as "C with classes". It keeps C's speed and control over memory, and adds tools for building large programs: classes and objects, templates, and a rich Standard Library.

Where C++ is used

AreaExamples
Games Unreal Engine and most big-budget games
Browsers Chrome, Firefox and Edge are largely C++
Databases and compilers MySQL, MongoDB, LLVM
Embedded and real-timecars, robots, medical devices, Arduino boards

A first look

C++
#include <iostream>
using namespace std;

int main() {
    cout << "Hello, C++!" << endl;
    cout << "2 + 3 = " << 2 + 3 << endl;
    return 0;
}

cout ("character output") sends text to the screen with the << operator, and endl ends the line. You'll take this apart in the next lesson.

C++ and C

Almost all C code is also valid C++, so everything in the C course applies. C++ adds:

FeatureWhat it gives you
cout / cintype-safe, easy input and output
classesbundle data and functions into objects
referencesa safer alternative to many pointer uses
std::string, std::vectortext and resizable lists without manual memory management
templatescode that works for any type

Compiled to machine code

Like C, C++ is compiled. On your own computer you'd write:

Terminal
g++ hello.cpp -o hello
./hello
Finished this lesson?Mark it complete to earn +20 XP and move your progress on.