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

科目名稱:資訊系統 與網路導論 開課系所:資訊工程 學系 任課教師
吳坤熹
系所別:
年級:
學號:
姓名:
考試日期
2011.10.19

(考試時間: 14:10-14:20)

  1. (10%) What will the following code display?

    #include <iostream>
    using std::cout;
    using std::endl;

    int main()
    {
        char name[] = "NCNU";
        unsigned mask = 0x03;

        cout << name << endl;
        for (int i=0; i<4; i++)
            name[i] |= mask;
        cout << name << endl;
        return 0;
    }







  2. (10%) What will the following code display?

    #include <iostream>
    using std::cout;
    using std::endl;

    int main()
    {
        int a[2][2] = { {1,2}, {3,4} };
        int i, j;

        for (i=0; i<2; i++)
        {
            for (j=0; j<2; j++)
                cout << a[i][j];
            cout << endl;
        }

        for (i=0; i<2; i++)
            for (j=0; j<2; j++)
                a[i][j] = a[i][j] * (i==j?1:0);

        cout << endl;
        for (i=0; i<2; i++)
        {
            for (j=0; j<2; j++)
                cout << a[i][j];
            cout << endl;
        }

        return 0;
    }