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

科目名稱:程式設計 開課系所:資訊工程 學系 考試日期 2017.3.22
系所別:
年級:
學號:
姓名:
考試時間 10:40-10:55
  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).
    // Size of an Array
    #include <iostream>
    using std::cout;
    using std::endl;

    int main()
    {
        int a[5] = { 0, 2, 4, 6, 8 };
        cout << sizeof(a[0]) << endl;
        cout << sizeof(a) << 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).
    // Character Array
    #include <iostream>
    using std::endl;
    using std::cout;

    int main()
    {
        char s[] = "NCNU";
        char horse[] = "~/-\\^";
        char c = horse[4];
        char* p = &horse[4];
        cout << sizeof (s) << c << (p - horse) << endl;
        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
    #include <iostream>
    using std::cout;
    using std::endl;

    int main()
    {
        int n = 2017;
        int* p = &n;
        cout << (*p) ++ << endl;
        cout << (*p) << endl;
        cout << ++ (*p) << endl;
        return 0;
    }