Multiple-choice questions.(單選題)
1.1. (2%) Which of the following is an illegal use of function put? (a) cout.put('A'); (b) cout.put("A"); (c) cout.put('A').put('\n'); (d) cout.put(65);
1.2. (2%) Assume that t is an object of class Test, which has member functions a(), b(), c() and d(). If the functions a(), b(), c() all return references to an object of class Test (using the dereference this pointer) and function d() returns void, which of the following statements will not produce a syntax error: (a) t.a().b().d(); (b) a().b().t; (c) t.d().c(); (d) t.a().t.d();
1.3. (2%) A function that modifies an array by using pointer arithmetic such as ++ptr to process every value should have a parameter that is: (a) A non-constant pointer to non-constant data. (b) A non-constant pointer to constant data. (c) A constant pointer to non-constant data. (d) A constant pointer to constant data.
1.4. (2%) A function prototype does not have to ______. (a) include argument names (b) end with a semi-colon (c) agree with the function header (d) match with all calls of the function
1.5. (2%) Recursion is memory-intensive because: (a) Recursive functions tend to declare many local variables. (b) Previous function calls are still open when the function call itself and the activation records of these previous calls still occupy space on the call stack. (c) Many copies of the function code are created. (d) It requires large data values.
1.6. (2%) static member functions: (a) Can use this pointer. (b) Can access only other static member functions and static data members. (c) Cannot be called until an object of their class is instantiated. (d) Can be declared const as well.
1.1 put 收一個 char;(b) 的 "A" 是字串(const char*),不能轉成 char;(c) 回傳 ostream& 可串接;(d) 65 轉成 'A' → (b)
1.2 a()、b() 回傳 Test& 可以一路接,最後 d() 回傳 void 沒問題;(b) 前面沒有物件;(c) void 後面不能再接 .c();(d) Test 裡沒有成員 t → (a)
1.3 要改內容:資料不能是 const;要 ++ptr:指標本身不能是 const → (a)
1.4 prototype 只需要參數型態,名稱可省(int max(int,int););(b)(c)(d) 都是必要的 → (a)
1.5 前面每層呼叫都還沒 return,activation record 全留在 call stack 上;function code 只有一份 → (b)
1.6 static member function 沒有 this,所以只能直接用其他 static 成員,也不能宣告 const;不需要物件就能用 Class::f() 呼叫 → (b)
1.1 (b) 1.2 (a) 1.3 (a) 1.4 (a) 1.5 (b) 1.6 (b)