國立暨南國際大學 100 學年度第一學期小考試卷                   (考試時間: 08:10-08:25)
科目名稱:資訊系統 與網路導論 開課系所:資訊工程 學系 任課教師
吳坤熹
系所別:
年級:
學號:
姓名:
考試日期
2011.11.4
  1. (10%) What will the following code display?
    // pointer to char
    #include <iostream>
    using std::endl;
    using std::cout;

    int main()
    {
        char *pstr = "AIRWOLF";
        cout << sizeof( pstr) << endl;
        cout << sizeof(*pstr) << endl;
        return 0;
    }

  2. (10%) What will the following code display?
    // char array
    #include <iostream>
    using std::endl;
    using std::cout;

    int main()
    {
        char c[] = "AIRWOLF";
        char* p;
        cout << sizeof(c) << " " << c << endl;
        p = c;
        cout << sizeof(p) << " " << p << endl;
        return 0;
    }

  3. (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).
    // Pointer Arithmetic
    #include <iostream>
    using std::endl;
    using std::cout;

    int main()
    {
        short data[5] = { 1, 3, 5 };
        short* pdata = &data[2];
        *(++pdata) = 2;
        *(pdata++) = 4;
        cout << *(pdata-1) + *pdata + *data - data[1] << endl;
        return 0;
    }