國立暨南國際大學 110 學年度第二學期小考試卷

科目名稱:程式設計 開課系所:資訊工程 學系 考試日期 2022.3.17
系所別:
年級:
學號:
姓名:
考試時間 08:15-08:30
  1. (10%) Consider a floating point value in IEEE 754 format. Its sign, exponent, and mantissa are 01000101110010010000000000000000. What is the value of this floating point number? Please write down your calculating process.
    6432




  2. (10%) Determine whether the syntax of the following code is correct or not.  If it is correct, predict its output.  If it is incorrect, point out the mistake(s).
    /* Linked List */
    #include <iostream>

    struct Node {
        int value;
        Node* next;
    };

    void print(Node* p) {
        while (p) {
            std::cout << p->value;
            p = p->next;
            if (p) std::cout << ' ';
        }
        std::cout << std::endl;
    }

    void insert(Node** aList, int v) {
        Node* p = *aList;
        if (p == NULL) {
            *aList = p = new Node;        // malloc(sizeof(Node))
            p->value = v;
            p->next = NULL;
        } else {
            while (p->next != NULL)
                p = p->next;
            p->next = new Node;
            p->next->value = v;
            p->next->next = NULL;
        }
    }

    int main()
    {
        Node* head = NULL;
        int a[] = { 1, 3, 5, 7, 2, 4, 6 };
        for (size_t i=0; i<sizeof(a)/sizeof(a[0]); ++i)
            insert(&head, a[i]);
        print(head);
        return 0;
    }

  3. (10%) Suppose the following program is compiled and run on a 64-bit computer (e.g., lilina).  What will be the output?
    /* sizeof */
    #include <iostream>
    using std::cout;
    using std::endl;

    int main()
    {
        const char* s[5] = { "Alfa", "Bravo", "Charlie", "Delta", "Echo" };
        cout << sizeof(s) << '\t' << sizeof(s[0]) << '\t' << sizeof(*s[0]) << endl;
        return 0;
    }