國立暨南國際大學 101 學年度第一學期小考試卷

科目名稱:計算機概論 開課系所:資訊工程 學系 考試日期 2012.11.23
系所別:
年級:
學號:
姓名:
考試時間 08:10-08:20
  1. (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).
    // Recursive function
    #include <iostream>

    int f(int n)
    {
        if (n == 0)
            return 2;
        else if (n == 1)
            return 1;
        else
            return f(n-1) + f(n-2);
    }

    int main()
    {
        std::cout << f(8) << std::endl;
        return 0;
    }



  2. (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).
    // Pointers as Arguments to a Function
    #include <iostream>

    void swap(int i, int* j)
    {
        int temp;
        temp = i;
        i = *j;
        *j = temp;
    }

    int main()
    {
        int a = 10;
        int b = 20;
        swap(a, &b);
        std::cout << a << '\t' << b << std::endl;
        return 0;
    }