C++ Basics

* - indicates a pointer to the variable, not the variable itself. Interpret this as "the contents of this address".

& - indicates a reference. This is useful as an arguement type for "pass by reference" rather than by value. Interpret this as "the address of".

  void foo(int &k){
    k = 37;
  } // the original k has now been modified!

int alpha; // a normal integer
int *ptrBeta; // the pointer to an integer - undefined as of the moment!
ptrBeta = α // ptrBeta now points to the integer alpha
*ptrBeta = 3; // the integer alpha is now 3

Converting a string to an integer:

  int i = atoi("37"); // use atol to convert to long, use atof to convert to float

Converting an integer to a string:

Strings:

strlen(s) - obtains the length of a string
strcpy(to,from) - copies the string "from" into the string "to". Beware of the "from" string being longer than the "to" string!

Random numbers:

  srand(47); // seeds the random number generator
  int r = rand(); // obtains the next random integer

Time:

  time_t now = time(0); // obtains the current time
  time_t local = localtime(&now); // converts it to the local time
   s = asctime(local); // converts it to a formatted string
  time_t then = time(0); // next time sample
  double elapsed = difftime(then,now); // elapsed time, in seconds?