C++ Basics

C++ Language Overview

Why C++?

REFERENCE: We have a good book for learning C++, Accelerated C++. Click on the link for information and to download all of the code for the examples in the book.

C++ compiling

Program Organization

Pre-Processing

Namespaces

Pass by Reference

#include <iostream>
#include <string>

using namespace std;

void func(int value, int * pointer, int & alias) {
    value = value + 1;        // no effect on calling argument
    *pointer = *pointer + 5;  // changes calling argument
    alias = alias + 10;       // also changes calling argument
}

int main(void) {
    int a = 10, b = 10, c = 10;
    func(a, &b, c);          // 2nd and 3rd parameters having same effect
    cout << a << ' ' << b << ' ' << c << endl;  // note explicit spaces
    // prints 10 15 20
    int &d = c;	         // d is now an reference to (alias for) c
    d = 30;              // changes c as well since they are aliases 
    cout << c << endl;
    // prints 30
}

See also C++ I/O and string notes.