國立暨南國際大學 100 學年度第一學期小考試卷                   (考試時間: 14:35-14:50)
科目名稱:資訊系統 與網路導論 開課系所:資訊工程 學系 任課教師
吳坤熹
系所別:
年級:
學號:
姓名:
考試日期
2011.11.9
  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).
    // array of pointer
    #include <iostream>
    using std::cin;
    using std::cout;
    using std::endl;

    int main()
    {
        char* greek[] = { "Alpha", "Beta", "Gamma", "Delta", "Epsilon" };
        // cout << greek << endl;    // This will print the starting address of the array
        cout << *greek << endl;
        cout << *(*greek) << endl;
        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).
    // array of pointers
    #include <iostream>
    using std::cin;
    using std::cout;
    using std::endl;

    int main()
    {
        char* greek[] = { "Alpha", "Beta", "Gamma", "Delta", "Epsilon" };
        cout << sizeof greek << endl;   // This will print the starting address of the array
        cout << sizeof *greek << endl;  // Hint: Array names can behave like pointers. (P.194)
        cout << sizeof greek[0] << endl;
        cout << sizeof(*(*greek)) << 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 to char
    #include <iostream>
    using std::cin;
    using std::cout;
    using std::endl;

    int main()
    {
        char* greek[] = { "Alpha", "Beta", "Gamma", "Delta", "Epsilon" };
        char pstr = *greek[4];
        cout << pstr << endl;      
        return 0;
    }