Notes from class, Jan 13 We've talked about many ways to pass parameters to functions default parameters (allows caller to omit trailing parameters if desired) pass-by-value A copy of the parameter is made - so function has its own private copy The function has no power to change the caller's variables pass-by-reference No copy of the parameter is made function shares caller's copy of the variable and can thus change it here's something new: const parameters with a const parameter, the function cannot change the value of the parameter - even its own copy. Typically, we use const parameters in conjunction with pass by reference. Example: bool verify_name(const string& name) { char ans; cout << "Is the correct name " << name << "?"; cin >> ans; if (ans == 'y' || ans == 'Y') return true; else return false; } If you insert the line name = "John"; in the above function, it will not compile, because name is a const parameter. This gives the caller assurance that the function won't alter its variables, even though the parameter is pass by reference. So you get the efficiency of not having to make a copy, but the security of the caller's variables at the same time. Note: You can have const parameters that are pass by value, but they are not usually that useful. Array review: Here's some examples about arrays to help you remember: int intarr[5]; // Declares an array of integers with 5 elements float fnums[3] = {6.2, 1.3}; // Declares array of floats, and initializes // the first two elements - the 3rd will be // set to 0 int arr[] = {1, 2, 3, 4, 5}; // Space for 5 integers automatically reserved cout << arr[3]; // outputs a 3 cout << arr[6]; // this compiles, but is a logic error - you shouldn't // access elements outside the bounds of the array // results are unpredictable for (int i=0, int total=0; i < 5; i++) total += intarr[i]; // adds the first 5 elements of the array Here's an exampe of how to pass an array to a function. If the function won't change the values in the array, then it's good practice to declare the array as a const parameter: int calc_total(const int arr[], int size) { int i; total(0); for (i=0; i < size; i++) total += arr[i]; return total; } Brand-new topic: c-style arrays (also known as character arrays) A character array behaves just like you'd expect an array of characters to behave, except that we assume that the arrays are null-terminated (end with a 0 or '\0'). This null-termination requires an additional space. Examples of declaring: char name[10]; char name2[] = {'J','a','n','e','\0'}; // Ew, but there's a better way char name3[] = "Mary"; // automatically reserves 5 spots, null-terminates; char name4[3] = "Joe"; // Error - there's not enough room for the '/0'