Professor: Tony Kusalik Time: 180 minutes
Format: Closed-Book† Total Marks: 107
Name: __________________________________________ Remember to record your
identity on the OpScan
Student Number: ____________________ NSID ___________ sheet as well
Directions
Please fill out the top of this booklet and the OpScan sheet with identification information. Failure
to provide this information will jeopardize your chances of getting credit for the exam. When you are
finished the exam, hand in both the exam booklet and the OpScan sheet.
This exam consists of two portions. The first portion, Parts A – C, contains matching,
multiple-choice, and true/false questions. That portion is to be answered in pencil on the OpScan
sheets provided. The remainder of the exam, Parts D – F, is to be completed in the space provided in
this exam booklet. If you must continue an answer (e.g. in the extra space on page 24), make sure
you clearly indicate that you have done so and where to find the continuation.
Make all written answers in Parts D – F legible; no marks can be given for answers that cannot be
deciphered. Do not give “extra answers”. Extra answers that are incorrect will result in your being
docked marks. If you find it necessary to make an assumption to answer a question, state that
assumption with your answer.
Be aware that the exam booklet has been printed two-sided. Question numbering in Parts A – C is
consecutive. Marks for each major question are given at the beginning of that question. There is
supplemental reference information on the last page(s) of the exam booklet. Make sure to check
what's there before answering any questions.
This is a closed-book† exam, so you cannot make use of computers, smart phones, or any
supplementary resources other than your optional “cheat sheet”. Also, calculators are not allowed.
Finally, if you have a cell phone with you, please make sure it is turned off. Good luck.
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
For marking use only:
A. OpScan / 6 D. ______ /26
B. OpScan / 54 E. ______ / 6
C. OpScan / 6 F. ______ / 9 Total: ______ / 107
† Closed book, except for an optional single 8.5×11-inch quick reference sheet (“cheat sheet”) of the student’s own
composition.
A. (1 mark each, 6 marks in total)
In this question you need to match shell (sh or bash) variables and their corresponding descriptions. The
possible responses are the following descriptions:
(a) all the files in the current working directory
(b) within a script, number of arguments or parameters on the command line
(c) exit status of most recently executed foreground command
(d) PID of the current (shell) process
(e) exit status of this shell
(f) PID of the process used to execute the last command
(g) within a script, the name of the command used to invoke the script
(h) within a script, the first command line parameter or argument given
(i) within a script, all command-line arguments or parameters given
For each of the variables below, indicate which of the responses (descriptions) above applies. Fill in the label
of your choice (i.e. description) on the OpScan sheet. Each description is to match one and only one variable.
Hence, some descriptions will not be used.
1. #
2. @
3. 0
4. 1
5. ?
6. $
B. (1 mark each, 42 marks in total)
For each of the following multiple-choice1 questions, indicate the answer that is the best response to the
question. Record your response in each case on your OpScan sheet, starting at question (line) 7.
7. In the context of SVN, a working copy is typically created with which of the following SVN commands?
(a) svn checkout
(b) svn mkdir
(c) svn copy
(d) svn import
(e) svn update
(f) Any of the above.
8. What is the character that can be typed on the keyboard as input to the shell and that will result in the
current foreground process being suspended?
(a) ^Z (control-Z)
(b) ^C (control-C)
(c) ESC (the escape character)
(d) DEL (the delete character)
(e) None of the above.
December 19, 2017 Cmpt 214 Final Examination
page 2
1. Or, as Peppermint Patty from the Peanuts comic strip would say, “mystical guess”
9. A Cmpt 214 student is trying to debug a program called calculator.c using gdb. She proceeds as follows:
bash-4.3$ gcc -Wall -Wextra -o calculator calculator.c
bash-4.3$ gdb calculator
GNU gdb (GDB) 7.12-16.mga6 (Mageia release 6)
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-mageia-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"…
Reading symbols from calculator...done.
(gdb) break main
Breakpoint 1 at 0x401c69
(gdb) run
Starting program: /student/214/test/calculator
Breakpoint 1, 0x0000000000401c69 in main ()
(gdb) info args
No symbol table info available.
(gdb) info locals
No symbol table info available.
(gdb) list calculator.c:10,20
No source file named calculator.c.
There appears to be a problem. The gdb session is not behaving as the student expected. What is the
source of the problem?
(a) The gdb command needed one more argument on the command line, the name of a “core file”
(produced by a previous run of calculator ).
(b) The -g option should have been given to the gcc command when calculator was compiled.
(c) The .o files of other modules constituting the calculator program were not included in the gcc
command.
(d) The first command given to gdb should have been “backtrace” rather than “run”.
(e) None of the above
10. Suppose a C program has a function definition that begins
int dispatch( unsigned trigger, int *data, float f(char) )
Which of the following statements is true in the context of the above statement?
(a) The third formal argument to dispatch() is a function that requires a char parameter and
returns a float.
(b) A call of the function dispatch() requires four parameters, an unsigned, an (int *), a float,
and a char.
(c) The function header will result in a compiler error because type “float f(char)” is erroneous.
(d) When the function is called, formal parameter data must be substituted by the address of an
integer in memory; it could not, for example, be substituted by the name of an array of integers.
(e) None of the above.
Cmpt 214 Final Examination December 19, 2017
page 3
11. Suppose that a programmer has a portion of C code designed to sum a list of numbers of type unsigned
int. The numbers are in a 1-dimensional array, v. There are SIZEOFV elements in the array. The
numbers being added are rather large, as is SIZEOFV, so the programmer wants to catch overflow —
should it happen — while the sum is being calculated. Which of the follow code fragments will reliably
accomplish what the programmer wants?
You can assume that i, sum, and prev_sum are already defined to be of type unsigned int, and
that the maximum value that can be stored in a variable of type unsigned int is the value of the
symbol UINT_MAX. You can also assume that sum has previously been initialized.
(a) for( i=0; i<SIZEOFV; ++i ) {
sum += v[i];
if( sum == 0 ) {
fprintf( stderr, “overflow!\n” );
break;
}
}
(b) for( i=0; i<SIZEOFV; ++i ) {
prev_sum = sum;
sum += v[i];
if( sum < prev_sum ) {
fprintf( stderr, “overflow!\n” );
break;
}
}
(c) for( i=0; i<SIZEOFV; ++i ) {
sum += v[i];
if( sum > UINT_MAX ) {
fprintf( stderr, “overflow!\n” );
break;
}
sum += v[i];
}
(d) for( i=0; i<SIZEOFV; ++i ) {
prev_sum = sum;
sum += v[i];
if( prev_sum != (sum - v[i]) ) {
fprintf( stderr, “overflow!\n” );
break;
}
}
(e) Any of the above will work.
12. Consider the following interaction with bash:
set - jingle bells all the way
shift
shift
If the following command
echo $2
is now executed, what will be output?
(a) jingle
(b) all
(c) the
(d) bells
(e) Nothing, since $2 will expand to a null string
(f) None of the above.
December 19, 2017 Cmpt 214 Final Examination
page 4
13. A makefile contains the following rule for “clean”:
clean:
! rm -f tree.o traversal.o test.o bintree.o
! rm -f example_82.o example_79.o
! rm -f bintree example_82 example_79
Unfortunately, when the user gives the command
make clean
make reports
make: `clean' is up to date.
How should the programmer successfully deal with this problem?
(a) Place the rule for clean as the first one in the makefile.
(b) Declare the target to be a “phoney” target via
.PHONY: clean
(c) Give the -f option to make(1), as in
make -f clean
(d) Give the -W option to make(1), as in
make -W clean
(e) None of the above.
14. Suppose a user has the following interaction with a LINUX/UNIX system:
bash-3.2$ time ./nqueens 6
A solution exists for N = 6
.Q....
...Q..
.....Q
Q.....
..Q...
....Q.
real! 0m27.317s
user! 0m27.242s
sys! 0m0.045s
In this particular case, the run time was
(a) 0m27.317s
(b) 0m27.242s
(c) 0m0.045s
(d) 0m27.317s + 0m27.242s or 0m54.559s
(e) 0m27.317s + 0m0.045s or 0m27.362s
(f) 0m27.242s + 0m0.045s or 0m27.287s
(g) The sum of the three times, i.e. 0m54.604s
(h) None of the above.