UMBC CMSC201, Computer Science I, Fall 1994 Section 0101, 0102 and Honors

Midterm Exam, version 1, Multiple Choice Section


Multiple Choice, 2 points each

To practice taking this section. Choose the best answer in the pop-up menu after each question to record your answer. To submit your answers for grading, click on the "submit for grading" button.

On lynx, use down arrow to move to the next question or choice. Hit return to make your selection.

  1. What is the value of the following expression?
         13 - 11 - 7 * 5 % 3 + 2 % 1
      

    a. -2
    b. 0
    c. 1
    d. 2

    Your answer:

  2. The expression 13 + 2.5
    a. has type double and value 15.5.
    b. has type int and value 15.
    c. has type double and value 15.
    d. has type int and value 16.

    Your answer:

  3. What is the output of the following code fragment?
        int a = 3, b = 17 ;
        
        a = b % a ;
        b = ++a + 5 ; 
        printf("a = %d, b = %d\n", a, b) ;
      

    a. a = 3, b = 8
    b. a = 2, b = 7
    c. a = 3, b = 7
    d. a = 2, b = 8

    Your answer:

  4. Execution of a break statement in the body of a for loop
    a. causes the entire program to terminate.
    b. causes the statement after the switch statement to be executed next.
    c. causes the current iteration of the loop to terminate and the next iteration to begin.
    d. causes the for loop to terminate and the statement after the body of the for loop to be executed next.

    Your answer:

  5. Trace the execution of the following if statements and determine the output of the code fragment.
        int a = 4, b = 3, c = 1 ;
        
        if ( a < b + 1 ) {
           printf("Tea, Earl Grey, Hot!\n") ;
        } else if ( a > b + c ) {
           printf("Ahead warp factor 9. Engage!\n") ;
        } else if ( a % b > c ) {
           printf("Warp core breach in 20 seconds!\n") ;
        } else {
           printf("I sense a lot of anxiety in this room.\n") ;
        }
      

    a. Tea, Earl Grey, Hot!
    b. Ahead warp factor 9. Engage!
    c. Warp core breach in 20 seconds!
    d. I sense a lot of anxiety in this room.

    Your answer:

  6. What is the effect of the following code?
        int i, total ;
      
        for (i = 1 ; i <= 15 ; i++) {
           if ( i % 3 == 0) printf("%d ", i) ;
        }
      

    a. It prints out the integers from 3 to 15.
    b. It prints out the multiples of 3 from 3 to 15.
    c. It prints out the sum of the integers from 3 to 15.
    d. It prints out the sum of the multiples of 3 from 3 to 15.

    Your answer:

  7. Let test be a Boolean variable. Note that there is an assignment in the condition of the first if statement. The output of the following program fragment is:
        test = FALSE ;
        if (test = FALSE) {
           printf("Beam down the landing party.\n") ;
        } else if (test == FALSE) {
           printf("Jim, he's dead.\n") ;
        } else {
           printf("Scotty, four to beam up.\n") ;
        }
      

    a. Beam down the landing party.
    b. Jim, he's dead.
    c. Scotty, four to beam up.
    d. No output is produced.

    Your answer:

  8. The following Boolean expression is equivalent to which of the given expressions?
        !( (n == 12) || (n > 15) )
      

    a. (n != 12) && (n <= 15)
    b. (n == 12) && (n > 15)
    c. (n != 12) || (n <= 15)
    d. (n != 12) && (n < 15)

    Your answer:

  9. Considering short circuit evaluation, after executing the following statments,
        int a = 5;
        bool test ;
    
        test = (3 > 2) && ( (a = a+3) > 5) ;
        test = (a > 7) || ( (a = a+4) > 24) ;
      

    a. test is TRUE and a is 12.
    b. test is FALSE and a is 5.
    c. test is FALSE and a is 9.
    d. test is TRUE and a is 8.

    Your answer:

  10. Which of the following is the function prototype for a function Lwaxana_Troi that takes 2 double parameters and does not return any values.
    a. Lwaxana_Troi(double, double)
    b. void Lwaxana_Troi(double, double)
    c. void Lwaxana_Troi(double x, y)
    d. double Lwaxana_Troi(double, double)

    Your answer:

To submit this section for grading click here:

Last Modified: Mon Oct 31 13:42:24 EST 1994

Richard Chang, chang@gl.umbc.edu