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

Quiz 2


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. The preprocessor directive #include "foo.h" instructs the compiler to read the contents of the file foo.h.

    Your Answer:

  2. A header file typically contains type definitions, function prototypes and the implementations of the function.

    Your Answer:

  3. If a function has a local variable x and there is also a global variable called x, then the statements in the function which use x refer to the local variable.

    Your answer:

  4. The prototype of a function is used mainly as a comment to the reader, but not useful to the compiler.

    Your answer:

  5. The term interface is used to describe the boundary between the implementation of a library of functions and programs that use the library.

    Your answer:

  6. On UNIX, the file foo.o usually contains the the machine language translation of the source code file foo.c.

    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. If the header file stdio.h is included twice in the same file, as in the following program fragment, then ...
      #include <stdio.h>
      #include <stdio.h>
      

    a. The preprocessor directives in the file stdio.h will keep the file from being read twice.
    b. The first #include will be ignored.
    c. The compiler will expect to see the implementation of two functions named stdio.
    d. The compiler will complain about a syntax error.

    Your answer:

  2. When a function makes changes to a global variable and then returns,
    a. the global variable may contain garbage values.
    b. the value in the global variable reverts to the value it had when the function was called.
    c. the changes to the global variable remain in effect.
    d. the global variable contains the value specified by the return statement.

    Your answer:

  3. The UNIX archive command ar is used to
    a. combine several object files into a library file.
    b. combine several library files into a source file.
    c. keep unused programs in secondary storage.
    d. compress large files to save disk space.

    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.

The questions in this section refer to the following program:


#include <stdio.h>
#include "genlib.h"
#include "simpio.h"

/* Function Prototypes */
int power2 ( int x ) ;
int power4 ( int x ) ;

/* The function implementations */

/* This function computes 4 raised to the power of x */
int power4 (int x) {
   return( power2(2*x)) ;
}

/* This function computes 2 raised to the power of x */
int power2 (int x) {
   int product, i ;

   product = 1 ;
   for (i = 1 ; i <= x ; i++) {
      product = 2 * product ;
   }
   return (product) ;
}

/* The main program */
main() {
   int a, b ;

   printf("? ") ;
   a = GetInteger() ;
   b = power4(a) ;
   printf("4^%d = %d\n", a, b) ;
}


The Questions:

  1. If you want to make the functions power2 and power4 available to your clients as part of a library of functions, what would the header file power.h contain? (Write down the entire header file. You may leave out the comments.)

    Click here for a sample solution.

  2. Suppose that you want to separately compile the implementation of the functions power2 and power4 in a file power.c. Outline the contents of the file power.c. (You don't need to repeat the C code for the functions.)

    Click here for a sample solution.

  3. Now that you have the functions power2 and power4 available to you, write a complete program with a main function which uses power2 and power4 to compute 2 cubed and 4 cubed and prints the results out.

    Click here for a sample solution.


Last Modified: Mon Sep 4 15:39:40 EDT 1995

Richard Chang, chang@gl.umbc.edu