View Assessment Result: Multiple Choice Quiz 2



Your performance was as follows:

1.
Consider the following code fragment. Thing *tp = new Thing; tp = new Thing; Which of the following is true concerning this code fragment?

(a) When executed, it creates two instances of Thing and makes the first point to the second.
(b) When executed, it creates a new instance of Thing and then loses all access to it as it creates yet another instance.
(c) When executed, it creates a new instance of Thing and then overwrites it by yet another instance.
(d) It will not compile.

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



2.

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

      bool  *bp;  int  x;
      bp = &x;


(a) The assignment should be *bp = &x;.
(b) A pointer to an int cannot be assigned to a variable that is a pointer to a bool.
(c) The & should be a *.
(d) Nothing

Correct answer is (b)

Your score on this question is: 0.00

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



3.
Which of the following types of memory is most likely to cause the production of errors in a program?

(a) The free store.
(b) Automatic memory.
(c) Static memory.
(d) They are all equally dangerous in C++.

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



4.

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) Version 1 uses a linked list of strings, but version 2 uses an array.
(c) Version 1 uses one long array of chars, but version 2 uses several small arrays
(d) None

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



5.

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) II only
(b) III only
(c) I only
(d) none

Correct answer is (c)

Your score on this question is: 10.00

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



6.
The Golden Rule for memory management in C++ is that

(a) every call to new must have a matching call to delete
(b) allocation must always come before deallocation
(c) every programmer-defined call to new will be matched by the compiler by a call to delete
(d) memory should always be initialized after allocation

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



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

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



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 has no effect.
(b) It zeroes out the whole array.
(c) It rotates the array 1 place to the left.
(d) It reverses the array.

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



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

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



10.

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

      Thing  *ptr = new Thing;
      ptr = NULL;


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

Correct answer is (b)

Your score on this question is: 0.00

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



Go to top of assessment.

Total score: 80.00