CS C++
Quiz 3
  1. True or False: When a function is called, the number of arguments should be the same as the number of parameters in the function's prototype.

  2. True or False: A function prototype must include names and types for all parameters.

  3. True or False: The definition of a function must appear in your program file before any calls to that function.

  4. A function f which takes two integer parameters and does not return any value could have the function prototype:
    (a) f(int, int);
    (b) void f(int);
    (c) void f(int, int);
    (d) int f(void, void);

  5. Write down the output of this program.
    int deep(int, int);
    int space(int);
    
    int main()
    {
        int a = 1, b = 2, c = 3;
        b = space(c);
        cout << "main: a = " << a << ", b = " << b << ", c = " << c << endl;
    }
    
    int deep(int x, int y)
    {
        int z;
        z = x - y;
        cout << "deep: x = " << x << ", y = " << y << ", z = " << z << endl;
        return(z);
    }
    
    int space(int c)
    {
        int a = 1, b;
        b = c * 2 + a;
        a = b + 5;
        c = deep(a, b);
        cout << "space: a = " << a << ", b = " << b << ", c = " << c << endl;
        return(b);
    }
    

  6. Write a function hundreds which, given an integer argument, returns the digit in the hundreds place. If the number is less than 100, it should return 0. So hundreds(1234) should return 2, and hundreds(1001) and hundreds(95) should both return 0.