C++ for Unix quick-reference, with C variations

Mostly description by example - not much text.

Program layout

  1. Pre-processor statements (#include)

  2. Constant definitions

  3. Type definitions

  4. Function declarations

  5. Main function
    1. main header
    2. variable declarations
    3. statements

  6. Function bodies
    1. function header
    2. variable declarations
    3. statements
    #include <iostream.h>
    
    const int SIZE = 20;
    typedef float floatarray[SIZE];
    
    void printarray(floatarray arr);
    
    void main()
    {
       floatarray myarray;
       for (int index = 0; index < SIZE; index++) {
           myarray[index] = index * 1.5;
       }
       printarray(myarray);
    }
    
    void printarray(floatarray arr)
    {
       for (int index = 0; index < SIZE; index++) {
           cout << arr[index] << endl;
       }
    }
    

Data types and conversions


Variables, constants, and scope