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

科目名稱:計算機概論 開課系所:資訊工程 學系 考試日期 2012.11.9
系所別:
年級:
學號:
姓名:
考試時間 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).
    // sizeof operator
    #include <iostream>
    using std::cout;
    using std::endl;

    int main()
    {
        char* pstr[] = { "George Washington",
                        "John Adams",
                        "Thomas Jefferson",
                        "James Madison",
                        "James Monroe",
                        "John Quincy Adams"
                       };
        cout << sizeof pstr[5] << 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).
    // size of a char array
    #include <iostream>
    using std::cout;
    using std::endl;

    int main()
    {
        char str[][18] = { "George Washington",
                        "John Adams",
                        "Thomas Jefferson",
                        "James Madison",
                        "James Monroe",
                        "John Quincy Adams"
                       };
        cout << sizeof str[5] << endl;
        // What is the size of str[2]?   
        return 0;
    }


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

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