國立暨南國際大學 100 學年度第一學期小考試卷                   (考試時間: 10:30-10:40)
科目名稱:資訊系統 與網路導論 開課系所:資訊工程 學系 任課教師
吳坤熹
系所別:
年級:
學號:
姓名:
考試日期
2011.11.18
  1. (10%) Determine whether the following code has syntax errors or not.  If it is correct, predict its output.  If it is incorrect, point out the mistake(s).
    // pass-by-value
    #include <iostream>
    using std::cout;
    using std::endl;

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

    int main()
    {
        for (int j=1; j<5; j++)
            print_stars(j);
        return 0;
    }



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

    void swap(int* a, int* b)
    {
        int temp;
        temp = *a; *a = *b; *b = temp;
        return;
    }

    int main()
    {
        int i = 2011;
        int j = 8;
        swap(&i, &j);
        cout << i << '\t' << j << '\n';
        return 0;
    }