UMBC CMSC201, Computer Science I, Spring 1994 Sections 0101, 0102 and Honors

Quiz 3


True or False Questions, 1 point each

To practice taking this section. Select TRUE or FALSE in the pop-up menus 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 C arrays and pointers are equivalent.

    Your answer:

  2. In the course library, the type string is equivalent to a pointer to char.

    Your answer:

  3. In C, an array with ten elements is indexed from 1 through 10.

    Your answer:

  4. If str is a string variable that holds the string "The good life", then str[3] refers to the character 'e'.

    Your answer:

  5. In C, when an array is passed to a function, only the address of the array is passed to the function.

    Your answer:

  6. In C, a parameter is passed by reference when the address of a variable is passed to the function.

    Your answer:

  7. Selection sort is the fastest method of sorting any array of integers.

    Your answer:

  8. The declaration:
       typedef int *int_ptr ;
    
    creates a variable called int_ptr which can hold the addresses of integers.

    Your answer:

  9. The function calloc is used to dynamically allocate memory for an array.

    Your answer:

  10. If rec is a structure (or record) variable and number is a field of the structure, then the number field of rec is expressed as rec->number.

    Your answer:

To submit this section for grading click here:


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. Let p be a pointer to an integer and i be an integer variable. Which of the following is not a correct assignment?
    a. p = 0 ;
    b. p = 1 ;
    c. p = p + 1 ;
    d. p = &i ;

    Your answer:

  2. In C, the end of a string is marked by:
    a. a carriage return.
    b. a tab character.
    c. a period '.'.
    d. the null character '\0'.

    Your answer:

  3. By binary search, we can find the location of any number in a sorted array of 1 million integers using roughly
    a. 5 comparisons.
    b. 20 comparisons.
    c. 1 million comparisons.
    d. 1 trillion comparisons.

    Your answer:

  4. A segmentation fault occurs when:
    a. a program using pointers does not compile.
    b. a program using strings does not compile.
    c. a program tries to access a memory location forbidden by the operating system.
    d. a program tries to access a variable declared in a separate file.

    Your answer:

  5. The expression sizeof(int) refers to
    a. the largest number that can be stored in an int variable.
    b. the number of int variables declared in the current function.
    c. the number of bytes needed to store an int variable.
    d. the largest number of characters allowed in the name of an int variable.

    Your answer:

To submit this section for grading click here:


Short Answers, 4 points each

This section cannot be graded on-line. To practice taking the exam, jot down your answer and click on the button after each question to see a sample solution.

There are no intentional syntax errors in this section.

  1. What is the output of the following program?
          main () {
             int i, j, *p, *q  ;
          
             p = &i ;
             q = &j ;
             *p = 3 ;
             *q = *p + i ; 
             printf("i = %d, j = %d\n", i, j) ;
          }
          

    Click here for a sample solution.

  2. What is the output of the following program?
          void foobar (int A[]) {
             
             printf("A[0] = %d, A[1] = %d, A[2] = %d\n", A[0], A[1], A[2]) ;
             A[1] = 0 ;
          }
    
          main() {
             int A[3] = {1, 2, 3} ;
    
             foobar(A) ;
             printf("A[0] = %d, A[1] = %d, A[2] = %d\n", A[0], A[1], A[2]) ;
          }
          

    Click here for a sample solution.

  3. What is the output of the following program?
          void add_5 (int a, int *p) {
    
             *p = a  + 5;
          }
          
          main() {
             int x = 1, y = 3;
    
             add_5 (x, &x) ;
             printf("x = %d, y = %d\n", x, y) ;
             add_5 (x, &y) ;
             printf("x = %d, y = %d\n", x, y) ;
          }
          

    Click here for a sample solution.


Last Modified: Mon Sep 4 15:47:09 EDT 1995

Richard Chang, chang@gl.umbc.edu