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

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.
Which of the following statements properly allocates an array of 100 integers?

(a) int &A = new int[100];
(b) int *A = new (int) 100;
(c) int A = new int[100];
(d) int *A = new int[100];

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



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

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

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



4.
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 by the programmer, but destroyed by the compiler.
(c) They are created and destroyed by the programmer.
(d) They are created and destroyed by the compiler.

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



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[10]; delete A;
(b) int *A = new int[5]; A = new int[5]; delete [] A;
(c) int *A = new int[10]; delete [] A;
(d) int *A = new int[5]; A = 0; delete [] A;

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



7.

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 reverses the array.
(d) It rotates the array 1 place to the left.

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



8.

What is the effect of the following code fragment?

      int   A[100];
     for( int *p = A; p < A + 100; ++p )
          *p = 0;


(a) It zeroes out A[0]-many elements of array A.
(b) It produces an out-of-bounds error.
(c) It sets 100 pointers in A to 0.
(d) It zeroes out the 100 elements of array 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



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 + 2;
(b) p = A[2];
(c) p = ++(++A);
(d) p = A + 2;

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



10.
Which of the following libraries supports null-terminated strings?

(a) cwchar
(b) cstdlib
(c) string
(d) string.h

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



Go to top of assessment.

Total score: 100.00