June 2025
Intermediate to advanced
1093 pages
33h 24m
English
Having looked at an example program from start to finish in the previous section, I will now go into a little more detail. You will see the first formal definitions and learn to recognize the important language elements.
Let's build Listing 4.1 a little and let's take a closer look at the elements we already know.
// https://godbolt.org/z/ceT6o5zxd#include <iostream> // for std::cin, std::cout, std::endl#include <string> // std::stoivoid calculate(int n) { // a separate function using namespace std; // for std::cout and std::endl /* output divisors */ cout << "divisors of " << n << " are:\n"; if(n == 0) { cout << "0\n"; return; } // 0 is divisor of 0 for(int divider=1; divider <= n; ++divider) { // for divider=divider+1 ...
Read now
Unlock full access