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 overwrites it by yet another instance.
(c) It will not compile.
(d) When executed, it creates a new instance of Thing and then loses all access to it as it creates yet another instance.

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



2.

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

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


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

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



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

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

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



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



5.
Which of the following is true about variables with dynamic extent?

(a) They are destroyed only at the end of execution.
(b) They are created and destroyed by the programmer.
(c) They are created by the programmer, but destroyed by the compiler.
(d) They are created and destroyed by the compiler.

Correct answer is (b)

Your score on this question is: 0.00

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



6.

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

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



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

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

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 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.
Which of the following makes p point to the third element of an array A (i.e., point to A[2]) ?

(a) p = ++(++A);
(b) p = A + 2;
(c) p = A[2];
(d) p = *A + 2;

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.
The scope of a variable concerns

(a) the time of its existence
(b) its type
(c) its visibility within a program
(d) the amount of memory it occupies

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



Go to top of assessment.

Total score: 90.00