Sample Midterm #1
1. (4 points) If the current working directory is
/usr/bishop/tmp, give an absolute path name without any . or
.. directories in it for:
2. (5 points) If I wanted to send the output of the command
from to the file FROM.OUT, and the error messages to the
terminal, what would I type to the C shell?
3. (4 points) What command would I type to print a list of files that
have names ending in ".c" and that contain the string "<stdio.h>"?
4. (5 points) How can you delete a file named -i?
5. (8 points) How does the shell use the path variable (in C shell,
path; in Bourne shell, PATH)?
6. (15 points) What does the following print? If the ANSI standard
says that more than one output is possible, give them all and explain why more
than one is possible.
7. (14 points) Evaluate the expressions below, and give the values of
the named variables after the expression has been evaluated. If the expression
contains a syntax error, or if a value is undefined, say so. Treat each
part as separate; that is, assume the following variable values for all parts,
regardless of whether a previous part has changed them.
i = 2;
printf("%d %d %d\n", i++, i++, i++);
int a = 0, b = 4, c = 5, d = -2, x; double dx;
8. (15 points) What is the output of the following program:
- x = a++ ? b++ : c++; give values of x, a, b, c
- x = (a || b++) && (c++ || a++); give values of x, a, b, c
- x = b < c < b; give value of x
- x = a + b / c; give value of x
- x = (c % d) + ((c / d) * d); give value of x
- x = dx = 3.2; give value of x and dx;
- x = a < d, --c < b; give value of x
int i = 3;
void g(int i)
static int i = 0;
printf("%d\n", i + i);
register int i;
i = 5;
9. (15 points) What is the value of n after the following code
char charray = "A-DF123";
int n = 0, s = 1;
char *p = charray;
s = -s;
n = n * 10 + (p[-1] - '0');
n = s * n;
10. (15 points) In the following:
if (fgets(p, 1024, stdin) != NULL)
for(p = line; *p; p++)
putchar(`A'<=*p && *p<=`Z' ? *p-`A'+`a' : *p);
- What happens when this portion of the program is compiled?
- What happens when this portion of the program is executed and the user
types in the string "This is ECS40" followed by a carriage return