Arrays as parameters to functions

Terminology for passing arrays into functions is tricky. By definition, an array's value is its address. So you always pass arrays (containing primitive types such as ints) by value, but it acts like you are passing by reference. For example:
   main() {
      int a[10] = {5, 6 , 7, 8, 9, 10, 11, 12, 13, 14};
      doSomething(a);
      ...
   }

   void doSomething(const int a[]) {
      ...
   }
This creates the following memory picture. Even though   a   is passed by value, the address is copied since   a's   value is its address. Using or not using const differentiates passing by value from passing by reference.
          __     ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ 
 main:  a| -|-->| 5 | 6 | 7 | 8 | 9 | 10| 11| 12| 13| 14|
          --     --- --- --- --- --- --- --- --- --- --- 
                 ^ 
                 |
                 |
             +---|----------+
doSomething: |   |          |
             | +-|-+        |
             | | | | a      |
             | +---+        |
             +--------------+
Practice doing this yourself with the following program. What's the output?   Draw all the memory including the activation record.
#include ...
int veryBad = 25;
main() {
   int i = 20, j = 30;
   int a[5] = {1, 2, 3, 4, 5};
   doIt(a, a[2], a[2], a[2], i, j);
   cout << veryBad << "  " << i << "  " << j << endl;
   for (int i = 0; i < 5; i++) {
      cout << a[i] << "  ";
   }
   cout << endl << endl;
   return 0;
}

void doIt(int a[], int b, int c, int& d, int& e, int& f) {
   veryBad = 35;
   b = 2*e - 2;
   ++c;
   d += 5;
   e = (f < 0 ? c : b);
   f = a[2];
   a[2] = 5;
   cout << b << "  " << c << "  " << d << "  " << e
        << "  " << f << "  " << veryBad << endl;
   for (int i = 0; i < 5; i++) {
      cout << a[i] << "  ";
   }
   cout << endl << endl;
}
Did you get the following output?
38  4  5  38  8  35
1  2  5  4  5  

35  38  8
1  2  5  4  5  

Check to see if you accurately portrayed the memory: memory picture