A Tour of C++

My Notes on the C++ language based on the book - A tour of C++ by Stroustoup, various CPPCON videos and stack overflow articles.



before we proceed

Processor's Computational Model

Assembly Language <A little explanation about the assembly language>

HELlo world

#include <iostream>

using namespace std;

int main()


    cout << "Hello World!" << endl;

    return 0;


Compiling the program

Save the above program in a file called (say) main.cpp and compile it as following:

g++ main.cpp -o hello_world_exe

The above command should create an executable by the name 'hello_world_exe' in the same directory. 

Run the above executable as (you may omit the ./ depending on your PATH setting)


Statically typed language

C++ is a statically typed, compiled language.

It means that each variable/expression has a type associated with it and the type defines the operations, which can be performed on the type. 

For example:

int x = 0; // x is of type int

x = "some_string"; // ERROR! Cannot assign const char* to int (both types are different)

In a dynamically typed language, however, the above can be rewritten as:

x = 0

x = "some_string" # No Error here. Type of x changes from int to str


C++ is a compiled language. 

A compiler is a software that converts a source code from one language to destination language. The source and destination language can be same in certain cases (more on this later).

A processor understands machine instructions (not even assembly) and a compiler (for a given language, given OS and given HW) converts from the source language to the machine instruction possibly through a set of tool chain. Note that compilation for C++ is  not a single step process. 

A typical C++ compiler, say g++, usually has the following stages

Input C++ file -> Preprocessor -> Tokenizer -> Syntax Analyser (+Semantic analysis) -> Optimizers -> I[nstruction Selection -> Instruction Scheduling?] -> Register Allocation -> Code generation -> assembly output file

assembly output file -> assembler -> object code

object code -> linker -> machine code/executable (specific to an OS and HW. This file is NOT portable!)

All the above steps are implicitly handled by g++ (simplifying things here! More on separate compilation and linking later)

Why are executables os dependAnt?



For the "Hello World" program above, check the following:

g++ -E main.cpp (Output will be printed on the terminal. You may redirect it to file as: g++ -E main.cpp |& tee preprocessed.cpp. Note that preprocessed.cpp is a valid C++ file)

fundamental Data types 

DO NOTE that a lot of things on data types are "implementation defined". Be sure to not make any assumptions! Such as sizeof(int) is always 4.

Arithmetic types



Must be 1 byte (i.e. at least 8 bits. Note that some machines may have more than 8 bits per byte)


long long


long double