UMBC CMSC201, Computer Science I, Fall 1994 Section 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. To produce the string "tangled" from the string "tangle" and the character 'd', we can concatenate them using the function call:
       Concat("tangle",'d') ;
       

    Your answer:

  2. To declare an array A of integers indexed from 0 to 27 we use:
          int A[27] ;
          

    Your answer:

  3. In the following function prototype, the parameter A is really a pointer because no memory is allocated to store the elements of an array pointed by A.
          void foo(int A[]) ;
          

    Your answer:

  4. Let str1 and str2 be two string variables. After the statements:
          str1 = "Flying Circus" ;
          str2 = SubString(str1, 7, StringLength(str1) - 1) ;
          
    the string str2 holds the string "Circus".

    Your answer:

  5. To declare a variable ptr to hold the addresses of double variables, we should use the declaration:
           double &ptr ;
          

    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 A be an array of integers, then in the expression (A[i])++, the side effect of the expression
    a. adds 1 to the address of A.
    b. adds 1 to the array element A[i].
    c. adds 1 to the index i.
    d. none of the above.

    Your answer:

  2. Let p be a pointer to int variables and let n be an int variable. Then after the assignment p = &n, the value of the expression:
      *&*&*&*&p
      

    a. is the address of the pointer p.
    b. is the value stored in the variable n.
    c. is the address of the variable n.
    d. none of the above.

    Your answer:

  3. After execution of the following code fragment
      int i ;
      char c ;
      string str ;
      
      str = "3.14159 + 2.718" ;
      i = 0 ;
      while (TRUE) {
         c = IthChar(str, i) ;
         if (isspace(c)) break ;
         i++ ;
      }
      

    a. the value of c is a space.
    b. the value of c is any character but a space.
    c. the value of c is the character '9'.
    d. the value of c is the character '+'.

    Your answer:

  4. Let p be a pointer to int. Then, the statement
      p = p + 1 ;
      

    a. results in a syntax error.
    b. adds to p the value of sizeof(int *).
    c. adds 1 to the address stored in p.
    d. adds to p the value of sizeof(int).

    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.

  1. Write down the output of the program.
        #include <stdio.h>
        
        int munge(int A[], int size) ;
    
        main() {
           int X[15], result ;
           
           result = munge(X, 4) ;
           printf("X[0] = %d, X[1] = %d, X[2] = %d, X[3] = %d\n",
              X[0], X[1], X[2], X[3]) ;
           printf("result = %d\n", result) ;
        }
        
        int munge(int A[], int size) {
           int i ;
           
           for (i = 0 ; i < size ; i++){
              A[i] = size - i ;
           }
           return(A[0]) ;
        }
        

    Click here for the solution.

  2. Write down the output of the following program:
          #include <stdio.h>
          
          main() {
             int a = 5, b = 7, *ptr1, *ptr2 ;
             
             ptr1 = &a ;
             ptr2 = &b ;
             *ptr2 = *ptr1 + b ;
             ptr1 = ptr2 ;
             *ptr1 = a + b ;
             printf("a = %d, b = %d, *ptr1 = %d, *ptr2 = %d\n",
               a, b , *ptr1, *ptr2) ;  
          }
       

    Click here for the solution.

  3. Write down the output of the following program:
          #include <stdio.h>
          
          void foo(int *, int *) ;
          
          main() {
             int a = 1, b = 3;
             
             foo(&a, &b) ;
             printf("a = %d, b = %d\n", a, b) ;
             foo(&a, &a) ;
             printf("a = %d, b = %d\n", a, b) ;
          }
          
          void foo(int *p1, int *p2) {
             *p1 = *p2 + 5 ;
             *p2 = *p1 - 1 ;
          }
       

    Click here for the solution.


Last Modified: Wed Dec 14 11:39:13 EST 1994

Richard Chang, chang@gl.umbc.edu