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

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



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.

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

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 declares p to be a pointer to an integer?

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

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.
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 = 0; 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 (d)

Your score on this question is: 10.00

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



6.

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



7.
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 (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.

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

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



(a) The non-null characters of "word" are 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 null-terminated string "word" is 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



9.
The scope of a variable concerns

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

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.h
(d) string

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: 100.00