liveBook · Manning

C++

As explained in Modern C, Third Edition

C++ is a general-purpose compiled programming language with C compatibility and object-oriented, generic, and low-level programming features.

C expresses orders for a computer as an imperative program. A small example combines declarations, an array, a loop, and output to print each value and its square. section 1.0 section 1.1

Listing 1.1 The first example of a C program
/* This may look like nonsense, but really is -*- mode: C -*- * 1 /
#include <stdlib.h> 2 
#include <stdio.h>  
3 
/* The main thing that this program does. */ 4 
int main(int argc, [[maybe_unused]] char* argv[argc+1]) { 
// Declarations 5 
double A[5] = { 6 
[0] = 9.0, 7 
[1] = 2.9, 
[4] = 3.E+25, 8 
[3] = .00007, 
};
9 
// Doing some work 10 
for (size_t i = 0; i < 5; ++i) {  11 
printf("element %zu is %g, \tits square is %g\n", 
i,
A[i], 12 
A[i]*A[i]); 13 
}
14 
return EXIT_SUCCESS; 15 
}

The example initializes five array elements and prints each element with its square. section 1.0

A compiler translates C source into an executable for a particular platform. Correct C programs aim to be portable, but testing on one platform does not guarantee portability. Compiler warnings and errors can expose flaws such as an invalid main declaration or a missing declaration for printf. section 1.2 section 1.3

How Modern C, Third Edition covers it

How deep it goes
Works through a small array-and-loop program, while deferring the details of compiler translation.
Examples
Uses an array-and-loop program to print values and squares, plus a flawed program with compiler diagnostics.
What it assumes
Teaches basic program structure from an initial example and does not require prior programming experience.
What you can do after
Build it from scratch: write, compile, run, and incrementally correct a small C program.
How it connects
Connects imperative programming with compilers and portability across platforms.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern C, Third Edition. The section links point to the parts of the book it draws on.