const dest static how know quadratic collatz array return pointer dot or -> struct XXX { int a, b, c; double d, e; string f; int * g; } XXX() { a = 0; b = 0; c = 0; d = 0.0; e = 0.0; f = ""; g = NULL; } XXX(string s) { a = s.length(); cout << "object " << s << " created\n"; b = 0; c = 0; d = 0.0; e = 0.0; f = s; g = new int[a]; } ~XXX() { cout << "object " << f << " destroyed\n"; delete [] g; } }; creating { XXX v, w("some words"); XXX * p = new XXX("more words"); XXX A[25]; v.a = 0; v.b = ...... (* p).a = 0; is exactly p->a = 0; delete p; } int keep_count(int n) { static int total = 0; total += n; return total; } { a = keep_count(3); b = keep_count(1); c = keep_count(6); class AAA { const int a; // must be set in constr static const int b = 9; int x; static int y; ... }; to look at a need an object AAA thing; cout << thing.a to look at b, no object needed cout << AAA::a; int AAA::y = 0; AAA p, q; p.x += 1 has no effect on q.x p.y += 1 is the same as q.y += 1 sel sort for boundary = 0 to N smallest = boundary for position = boundary + 1 to N for ant = 0 to N / 2 if A[position] < A[smallest] smallest = position swap(...) collatz from 10 10 5 16 8 4 2 1 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1 int * collatz(int n) { int size = 16; int * sequence[size]; int length = 0; while (n != 1) { if (length >= size) { int * a = new int[size * 2]; copy all from squence[0 ... length - 1] into a delete [] sequence; sequence = a; size *= 2; } sequence[length] = n; length = length+1; if (n%2 == 0) n = n/2; else n = n*3+1; } return sequence; } void f() { int * A = new int[4]; variable A at memory loc 1000 int * B = A; int * C = new int[5]; before 1000: 75000 1001: 75000 1002: 75004: 75000: A[0] and B[0] 75001: A[1] 75002: A[2] 75003: A[3] and B[3] 75004: C[0] 75005: C[1] 75006: C[2] 75007: C[3] 75008: C[4] delete [] B before 1000: 75000 1001: 75000 1002: 75004 75000: recycled 75001: ... 75002: ... 75003: recycled 75004: C[0] 75005: C[1] 75006: C[2] 75007: C[3] 75008: C[4] at function exit 1000: recycled 1001: ... 1002: rec ... 75000: recycled 75001: ... 75002: ... 75003: recycled 75004: C[0] memory leak 75005: C[1] 75006: C[2] 75007: C[3] 75008: C[4]