View Assessment Result


Family Name: LAM
Given Name: Ka Lee
Login: 50336714
E-mail: 50336714@cityu.edu.hk
Status: Enrolled

Assessment Name: Multiple Choice Quiz 2
Instance: 2

Section: CITYU-L09
During: Fall 2002

For course: Data Structures and Algorithms
(DCO20105)

Corresponding to: SSD5
At: City University of Hong Kong



Your performance was as follows:


Total score: 90.00


1.

Which of the following define an array A of 10 pointers to integers?

  1. int *A[10];
  2. int (*A)[10];
  3. int &A[10];


(a) I
(b) None
(c) III
(d) II

Correct answer is (a)

Your score on this question is: 10.00

Feedback:
   See section 1.2.1 of the course notes.
   (a) No Feedback



2.
If A is an array of 100 integers, which of the following properly deallocates A?

(a) delete [] A;
(b) delete [100] A;
(c) delete A;
(d) delete A[100];

Correct answer is (a)

Your score on this question is: 10.00

Feedback:
   See section 1.2.1 of the course notes.
   (a) No Feedback



3.

The parameters in the main part of a program often take one of the two following forms.

    Version 1:  int  main( int argc, char **argv )
    Version 2:  int  main( int argc, char *argv[] )

What is the difference between the two?



(a) Version 1 uses a variable-size array, but Version 2 uses a fixed-size array.
(b) None
(c) Version 1 uses a linked list of strings, but version 2 uses an array.
(d) Version 1 uses one long array of chars, but version 2 uses several small arrays

Correct answer is (b)

Your score on this question is: 10.00

Feedback:
   See section 1.2.1 of the course notes.
   (b) No Feedback



4.

Consider the following declarations.

      int  (*f)(int);
      int   *g(int);

Which of the following correctly characterizes f and g?

  1. f is a pointer to a function from integers to integers, and g is a function from integers to pointers to integers.
  2. both f and g are functions from integers to pointers to integers
  3. f is a function from integers to pointers to integers, and g is a pointer to a function from integers to integers


(a) none
(b) I only
(c) III only
(d) II only

Correct answer is (b)

Your score on this question is: 10.00

Feedback:
   See section 1.2.1 of the course notes.
   (b) No Feedback



5.
Which of the following declares p to be a pointer to an integer?

(a) int &p;
(b) int p[]
(c) int **p;
(d) int *p;

Correct answer is (d)

Your score on this question is: 10.00

Feedback:
   See section 1.2.1 of the course notes.
   (d) No Feedback



6.
Each of the following fragments produces a memory leak EXCEPT:

(a) int *A = new int[5]; A = 0; delete [] A;
(b) int *A = new int[10]; delete [] A;
(c) int *A = new int[5]; A = new int[5]; delete [] A;
(d) int *A = new int[10]; delete A;

Correct answer is (b)

Your score on this question is: 0.00

Feedback:
   See section 1.2.1 of the course notes.
   (c) No Feedback



7.
C++ currently supports two types of strings: null-terminated C-style strings, and the string class in the Standard Library. Which of the following claims is false?

(a) For simple tasks dealing with many short strings, null-terminated strings are the implementation of choice.
(b) The string class provides more operations than the C string library.
(c) Null-terminated strings can be processed efficiently with pointers.
(d) A C++ program may use either null-terminated strings or the string class, but not both.

Correct answer is (d)

Your score on this question is: 10.00

Feedback:
   See section 1.2.1 of the course notes.
   (d) No Feedback



8.

Consider the following code fragment.

      int  A[100], *p, *q;
      for( p = A, q = p + 99; p < A+100; p++, q-- )
            swap( p, q );

Execution of this code fragment has what effect on the array A?



(a) It rotates the array 1 place to the left.
(b) It reverses the array.
(c) It zeroes out the whole array.
(d) It has no effect.

Correct answer is (d)

Your score on this question is: 10.00

Feedback:
   See section 1.2.1 of the course notes.
   (d) No Feedback



9.

Consider the following code fragment.

      char  *str1 = "word";
      char  *str2;
      str2 = str1;

Which of the following correctly characterizes the effect of executing this fragment?



(a) The pointer str2 is set so as to point at the first character in the null-terminated string "word".
(b) The non-null characters of "word" are copied to str2.
(c) The null-terminated string "word" is copied to str2.
(d) Nothing is changed.

Correct answer is (a)

Your score on this question is: 10.00

Feedback:
   See section 1.2.1 of the course notes.
   (a) No Feedback



10.

What, if anything, is wrong with the following code fragment?

      Thing  *ptr = new Thing;
      ptr = NULL;


(a) When executed, it will create an instance of Thing and then remove the only reference to this instance without destroying it first.
(b) When executed, it will create an instance of Thing and then overwrite it with NULL.
(c) Nothing
(d) When executed, it will assign a NULL pointer to a variable that is a pointer to a Thing.

Correct answer is (a)

Your score on this question is: 10.00

Feedback:
   See section 1.2.1 of the course notes.
   (a) No Feedback



Go to top of assessment.

Total score: 90.00