C++ Notes: Example - pop

This function removes, and returns, the value at the end (top) of an array.

int pop(int a[], int& n) {
   // function:
   //    Reads from cin until array full or to an EOF.
   // parameters:
   //    a       in     array of values.
   //    n       inout  number of values in a, a[0]..a[n-1]
   // returns: 
   //   value that was at the end (top) of the array values.
   if (n <= 0) {
      ;// ERROR - return special value, halt, throw exception, or expand array.
   return a[n];