next up previous
Next: About this document

centering17

name:

  1. (5 pts) Give the UNIX command needed to email the file memo.txt to user bob3 of the system slowcomputer.psu.edu. The message should arrive with the subject line: a memo for you. You can assume that the file memo.txt is in the current working directory.



  2. Suppose your userid is jill27, and your current working directory is assignments, which is a subdirectory of your home directory. You want to use vi to edit the file toMom.txt, which is in the directory correspondence, also a subdirectory of your home directory.
    1. (6 pts) Is it possible to start editing that file with vi using only one UNIX command? If so, give that command. If not, give the sequence of UNIX commands required.






    2. (4 pts) Now suppose that you copy the file toMom.txt from my home directory (taw2) to your correspondence directory without changing the file name. What happens to your original toMom.txt file?





  3. (4 pts) What value would the following segment of C code print?
    int i = 27;
    
    printf("%d", (i <= 20)? i - 1: i + 1);
  4. Given the following declarations:
    int i1 = 0, i2 = 1, i3 = 2;
    float f1 = 3.0, f2 = 4.0;
    double d1 = 5.0, d2 = 6.0;
    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. If the result is a float or double, your answer only needs to show one place after the decimal point.
    1. (4 pts) i1 - i2 + (float) d1


    2. (4 pts) d1 * f1 / i1 + f2


    3. (4 pts) i3 / (int) f2


    4. (4 pts) i3 - f2 * d1


  5. (5 pts) What is the value of variable count when the following program finishes execution?
    #include <stdio.h>
    
    main() {
      int count = 1;  
    
      do {
        count++;
        if (count > 5) exit(1);
      } while (count <= 10);
      if (count > 8) count = 23;
      else count = 24;
    }
  6. Consider the following for loop.
    int i, sum = 0;
    
    for (i = 2; i <= 10; i += 2) {
      printf("The current value is %d\n", i);
      sum += i;
    }
    1. (5 pts) What is the value of sum after the for loop executes?


    2. (10 pts) Write a while loop that produces the same output and final value of sum as this for loop.









  7. (5 pts) Suppose you are editing the first line of a text file with vi, and vi is currently in command mode. Give the sequence of keystrokes needed to add the word and to the end of the tenth line of the file and return to command mode. (In other words, what keys would you have to press to make this change?) Indicate arrow keys by drawing an arrow pointing in the appropriate direction, and indicate special keys by enclosing their names in angle brackets (i.e. <Enter> or <Esc>).



  8. (6 pts) Suppose that all users have read, write, and execute permission on my home directory. Executing ls -l while in that directory produces:
    -rw-r--r--  1 taw2         3289 Jan 19 11:47 vi.txt
    Who has permission to change the contents of the file vi.txt? Who has permission to look at the contents of this file?
  9. (5 pts) What output would the following segment of C code produce?
    char c = 'b';  
    
    switch (c) {
      case 'a': printf("the value of c is a\n");
                break;
      case 'c': printf("the value of c is c\n");
                break;
      case 'b': printf("the value of c is b\n");
      case 'd': printf("the value of c is d\n");
      default : printf("the value of c is unknown\n");
                break;
    }
  10. 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;
    double d1 = 5.0, d2 = 6.0;
    1. (3 pts) ((i2 > 7.0) || (!(d1 == f1)))


    2. (3 pts) ((f1 != 3) && ((f2/i1) == 7))


    3. (3 pts) ((f1 != 3.0) || ((f2/i1) == 7))


  11. (4 pts) What mistake does the following C program contain? (Lack of comments is poor style, but not a mistake.)
    #include <stdio.h>
    const int foo = 10;
    
    main() {
      foo = 37;
      printf("%d\n", foo);
    }
  12. (8 pts) Why does every user of a UNIX system need both a userid and a password?












  13. (8 pts) Why do C programs have to be compiled before they can be run?



next up previous
Next: About this document

Tim Wahls
Tue Sep 24 14:30:13 EDT 1996