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

Final Exam, 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. In the following code fragment, the Boolean expression in the if statement contains an assignment. What output is produced?
          bool choose = FALSE ;
    
          if ( choose = TRUE ) {
             printf("Loose it in a river\n") ;
          } else if (choose) {
             printf("Toss it in a volcano\n") ;
          } else {
             printf("Wear it on your finger\n") ;
          }
    

    a. Loose it in a river
    b. Toss it in a volcano
    c. Wear it on your finger
    d. No output is produced

    Your answer:

  2. Which of the given expressions is equivalent to the following expression for all values of the integer variables elf and man ?
          (elf == 3) && (man == 9)
    

    a. !( (elf != 3) || (man != 9) )
    b. !( (elf != 3) && (man != 9) )
    c. ( (elf != 3) || (man != 9) )
    d. ( (elf == 3) || (man == 9) )

    Your answer:

  3. According to the rules of short circuit evaluation, after the following code fragment is executed
          bool flag = FALSE ;
          int a = 1 ;
    
          flag = (a > 1) || ( a++ > 4 ) ;
          flag = flag || ( a++ > 1 ) ;
    

    a. flag is TRUE and a is 1.
    b. flag is TRUE and a is 2.
    c. flag is TRUE and a is 3.
    d. flag is FALSE and a is 1.

    Your answer:

  4. After the declaration:
          typedef struct tag {
             int height ;
             double weight ;
             double wealth ;
          } dwarf ;
    

    a. dwarf is a new data type which can be used to declare variables as pointers to a record.
    b. dwarf is a new data type which can be used to declare variables as records.
    c. dwarf is a variable which can hold a pointer to a record.
    d. dwarf is a variable which can hold a record.

    Your answer:

  5. What is the value of the following expression?
        13 % 9 - 7 / 3 - 1
    

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

    Your answer:

  6. What is the output of the following code fragment?
          int n = 2, m = 3, *p ;
        
          p = &n ;
          *p = n + m ;
          p = &m ;
          m = *p - n ;
          printf("%d %d %d\n", n, m, *p) ;
    

    a. 2 3 5
    b. 2 5 5
    c. 5 0 5
    d. 5 -2 -2

    Your answer:

  7. Which of the following is a function prototype of a function that takes two parameters of type pointer to integer and does not return any value.
    a. void f (int, int) ;
    b. int *f (void, void) ;
    c. void f (int *, int *) ;
    d. f(void, int *, int *) ;

    Your answer:

  8. One purpose of a header file is to
    a. provide type declarations and function prototypes needed to use a library.
    b. make sure that the main program is not compiled twice.
    c. hide static global variables from the main program.
    d. all of the above.

    Your answer:

  9. When an array parameter is passed to a function
    a. the elements of the actual array parameter are copied into the elements of the formal array parameter.
    b. the elements of the formal array parameter are copied into the elements of the actual array parameter.
    c. the formal parameter is a pointer that holds the address of the actual array parameter.
    d. the programmer must write code which allocates enough space for the function to store the array.

    Your answer:

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

    a. a = 13, b = 14
    b. a = 14, b = 14
    c. a = 14, b = 15
    d. a = 15, b = 15

    Your answer:

  11. What is the output of the following code fragment?
       int start, stop ;
       string data ;
    
       data = "There and back again" ;
       start = stop = 6 ;
       while ( !isspace(IthChar(data,stop)) ) {
          stop ++ ;
       }
       printf("%s\n", SubString(data,start,stop-1) ) ;
       
    

    a. and
    b. and back again
    c. There and back again
    d. No output is produced

    Your answer:

  12. What is the effect of the following loop?
          int i = 0 ;
      
          while (TRUE) {
             if (i > 15) break ;
             i = i + 3 ;
             printf("%d ", i) ;
          }
    

    a. It prints out multiples of 3 from 0 to 12 (inclusive).
    b. It prints out multiples of 3 from 3 to 12 (inclusive).
    c. It prints out multiples of 3 from 3 to 15 (inclusive).
    d. It prints out multiples of 3 from 3 to 18 (inclusive).

    Your answer:

To submit this section for grading click here:



Last Modified: Wed Jan 4 14:08:57 EST 1995

Richard Chang, chang@gl.umbc.edu