Introduction

Bjarne Stroustrup developed C++ from the C programming language. It added "facilities for better type checking, data abstraction, and object-oriented programming" to C (stroustrup.com).

The ubiquity of C in system programming is because of its zero-overhead principle and its higher level of abstraction than writing in assembly. C++ adheres to these principles as well.

It is now "one of the world's most widely used, high-performance, computer-programming languages" (Deitel et al.).

Sample C++ code

A simple C++ program looks like the following.

#include <cstdio>

int main() {
  printf("Hello, world!\n");
  return 0;
}
  • At the top part of your code, you #include (import) the libraries that you want to use. In this case, we include cstdio that defines printf().
  • All C++ programs have the main() function as its entry point. Your program will start running from this function.
  • The main() function's return value (if you write any return statement) would denote the exit code of your program; it defaults to 0. (Exit code 0 generally means your program ran succesfully.)

The compiler tool chain

To convert your source code into an executable program, the C++ compiler tool chain (or tool chain) is a collection of these three elements that run one after another:

  • The preprocessor performs basic source code manipulation (e.g. include information about the libraries that you used). For each file processed, it outputs a single translation unit.
  • The compiler reads a translation unit and generates an object file (it contains data and instructions in an intermediate format most people won't understand).
The compiler's job
The compiler's job (Source: learncpp.com)
  • The linker reads object files, links them together (along with library codes), and generates a program.
    The linker's job
    The linker's job (Source: learncpp.com)

References