next up previous
Next: About this document

centering17

name:

  1. Given the following declarations:
    int i1 = 0, i2 = 1, i3 = 2;
    float f1 = 0.0, f2 = 4.0;
    double d1 = 5.0, d2 = 6.7;
    Give the result of evaluating each of the following expressions and the type of that result, or indicate that evaluating the expression would cause a run-time error in a C program. (In other words, if the expression does not cause a run-time error, your answer for that expression should consist of both a value and a type.) If the result is a float or double, your answer only needs to show one place after the decimal point.
    1. (3 pts) (int) d2 + i2 * (double) f2
    2. (3 pts) 8.3 + f2 / (2 * i2 + i3) - f2
    3. (3 pts) f1 / (float) d1
  2. Indicate whether each of the following C expressions evaluates to true (not 0), false (0), or causes a run time error when evaluated, given these declarations:
    int i1 = 0, i2 = 1, i3 = 2;
    float f1 = 3.0, f2 = 4.0, f3 = 0.0;
    double d1 = 5.0, d2 = 6.0;
    1. (3 pts) (!((i2 + f1) < 9) || (f2 == d2))
    2. (3 pts) ((d1 == 5) || ((d2 / f3) == 0))
    3. (3 pts) ((d2 / f1 == i3) && ((d1 / i1) == 8.7))
  3. (5 pts) You are in command mode while editing a large file (over 100 lines) with vi. You do not know the line number of the current cursor position. Give the sequence of keystrokes needed to add a semicolon (;) to the end of line 52 of the file and return to command mode. Indicate special keys by enclosing their names in angle brackets (i.e. <Enter> or <Esc>).
  4. (5 pts) Suppose you are reading your email using the mail program. Give the sequence of keystrokes needed to save message number 12 in file frombob in the current working directory.
  5. (5 pts) What output does the following program produce when it is run?
    #include <stdio.h>
    
    main() {
      int a = 4;
    
      if (a = 3) printf("the value of a is: %d", a);
      else printf("the value of a + 1 is: %d", a + 1);
    }
  6. (6 pts) Your current working directory is correspondence, which is a subdirectory of your home directory. The protection modes in force for directory pub (also a subdirectory of your home directory) are:
    drwxrw----
    Give a sequence of Unix commands that will change the protection modes in force for directory pub to the following:
    drwxr-xr-x
  7. (5 pts) What output does the following program produce when it is run?
    #include <stdio.h>
    
    main() {
      int ball_club = 1;
    
       switch (ball_club) {
        case 0: printf("Mets\n");
                break;
        case 1: printf("Cubs\n");
        case 2: printf("Royals\n");
                break;
       default: printf("Cardinals\n");
      }
      printf("*** End of baseball team listing ***\n");
    }
  8. (5 pts) Give the Unix command needed to copy the file afile from directory /usr/local/bin to your current working directory. Your copy should have the same name as the original. You are not allowed to use more than one Unix command in your answer.
  9. (15 pts) Write a C function that takes an integer parameter n and a double parameter d. If n is less than 0, your function should return tex2html_wrap_inline48 . If n is greater than or equal to 0, your function should return tex2html_wrap_inline52 . Recall that tex2html_wrap_inline52 means d multiplied with itself n times, i.e. tex2html_wrap_inline60 . You are not allowed to call any standard (library) C functions in your function. You may use exactly one return statement in your function.
  10. (18 pts) What output does the following program produce when it is run? You only need to show one place after the decimal point for floats and doubles.
    #include <stdio.h>
    int x = 4;
    int y = 5;
    
    void inc2(int *);
    double times2(double);
    
    main() {
      int y = 3, z = 5;
      float f;
      double d = 7.0;
    
      inc2(&z);
      printf("The value of x is %d and y is %d and z is %d\n", x, y, z);
      f = (float) times2(d);
      printf("The value of x is %d and f is %f and d is %lf\n", x, f, d);
    }
    
    void inc2(int *x) {
    
      *x = *x + 2;
      y = y + 2;
    }
    
    double times2(double z) {
    
      x = x * 2;
      z = z * 2;
      return (z);
    }
  11. (6 pts) Why is it necessary to include header files if you want to use library functions in a program?
  12. (6 pts) What output does the following program produce? You only need to show one place after the decimal for floats and doubles.
    #include <stdio.h>
    
    main() {
      int a = 7;
      double d;
    
      d = (a > 8)? a + 2.0: a + 1.0;
      printf("The value of d is %lf.\n", d);
      do {
        a++;
        printf("The value of a is %d.\n", a);
        exit(1);
      } while (a < 3);
      printf("The value of a is %d.\n", a);
    }
  13. (6 pts) Name a situation in which pass-by-address parameters are necessary, and explain why they are necessary in that situation.



next up previous
Next: About this document

Tim Wahls
Wed Mar 19 11:33:18 EST 1997