(10%)
Determine
whether the following code is correct or not. If it is
correct, predict its output. If it is incorrect, point out the
mistake(s).
// Default Value of Parameters (P.302)
// Static Variables in a Function (P.283)
#include <iostream>
using std::endl;
using std::cout;
int pop(int n = 1)
{
static unsigned short array [] = { 0, 1, 2, 3, 4, 5,
6, 7, 8, 9, 10 };
static unsigned short length = sizeof array / sizeof
array[0];
while (n-- > 1)
length--;
return array[--length];
}
int main()
{
cout << pop(2) << endl;
cout << pop(1) << endl;
cout << pop( ) << endl;
return 0;
}