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

    struct record {
        int number;                                      
        record* pNext;                  
    };

    void print(record* p)  // pass the pointer by value
    {
        for (; p != NULL; p = p->pNext)
            cout << p->number;
        cout << endl;
    }
    int main()
    {
        record Node1, Node2, Node3, Node4, Node5;
       
        Node1.number = 1; Node1.pNext = NULL;
        Node2.number = 2; Node2.pNext = &Node1;
        Node3.number = 3; Node3.pNext = &Node2;
        Node4.number = 4; Node4.pNext = &Node3;
        Node5.number = 5; Node5.pNext = &Node4;

        print(&Node3);    // Will the pointer be changed after this function call?
        print(&Node3);
       
        return 0;
    }



  2. (10%) Determine the output of the following code.
     // dynamic memory allocation
    #include <iostream>
    using std::cout;
    using std::endl;

    int main()
    {
        int* p = new int[7];
        cout << sizeof(p) << endl;
        delete p;    // See P.203 deleting an array
        cout << sizeof(p) << endl;

        return 0;
    }