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

科目名稱:計算機概 論 開課系所:資訊工程 學系 考試日期 2019.11.14
系所別:
年級:
學號:
姓名:
考試時間 08:20-08:30
  1. (10%) Determine whether the syntax of the following code is correct or not.  If it is correct, predict its output.  If it is incorrect, point out the mistake(s).
    // *(a + i) == a[i]
    #include <iostream>
    using std::cout;

    int main()
    {
        int a[] = { 1, 2, 3, 4, 5 };
        int b[] = { 6, 7, 8, 9, 10 };
        for (int i=0; i<5; ++i)
        {
            * (a + i) *= * (b + i);
            cout << a[i];
        }
        return 0;
    }


  2. (10%) Determine whether the syntax of the following code is correct or not.  If it is correct, predict its output.  If it is incorrect, point out the mistake(s).
    #include <iostream>
    using std::cout;

    void stars(n);  // function prototype

    int main()
    {
        stars(5);
        stars(5);
        return 0;
    }

    void stars(int n)
    {
        int i;
        for (i=0; i<n; ++i)
            cout << '*';
        return;
    }

  3. (10%) Determine whether the syntax of the following code is correct or not.  If it is correct, predict its output.  If it is incorrect, point out the mistake(s).
    // pass by reference
    #include <iostream>
    using std::cout;
    using std::endl;

    void stars(int& n)
    {
        for ( ; 0<--n; ) cout << '*';
    }

    int main()
    {
        int n = 6;
        stars(n);
        cout << n << endl;
        return 0;
    }