CS 2505 Final Exam Flashcards
Which of the following are valid ways to pass information about an array back to the calling function?
(Mark all that apply)
a. Pass the array as a parameter to the called function and modify the contents directly in the called
function.
b. Return a pointer to a statically allocated array declared within the called function.
c. Return an array from the called function.
d. Return a pointer to a dynamically allocated array declared within the called function.
a. Pass the array as a parameter to the called function and modify the contents directly in the called
function.
d. Return a pointer to a dynamically allocated array declared within the called function.
Which of the following are true of the linker? (Mark all that apply)
a. The linker turns our C source code into assembly code, which is still human readable but closer to
what the computer can read.
b. The linker is responsible for resolving functions used in one file but created in another.
c. The linker creates an executable from object files (.o files).
d. The linker only runs if we have multiple C files.
b. The linker is responsible for resolving functions used in one file but created in another.
c. The linker creates an executable from object files (.o files).
You have been working on a homework that has source code files shapes.c, shapes.h, and sh_main.c
(which has your main() function). Which of the following compile lines would correctly create an
executable called shape_fun, turn on the warnings we have discussed in class, and turn on debugging
symbols?
a. gcc -o shape_fun -Wall -Wextra -g sh_main.c shapes.c
b. gcc -o -Wall -Wextra -g shape_fun sh_main.c shapes.c
c. gcc -o shape_fun -Wall -debug sh_main.c shapes.c shapes.h
d. gcc sh_main.c shapes.c shapes.h -Wall -Wextra -debug -exe shape_fun
a. gcc -o shape_fun -Wall -Wextra -g sh_main.c shapes.c
Which of the following is NOT a command to get to your home directory in rlogin?
a. cd
b. cd /home
c. cd /home/<classification>/<PID>
d. cd ~</PID></classification>
b. cd /home
What happens when the following command is run? (You may assume that the files main.c, vector.c,
and vector.h exist in the current working directory.)
tar -cf main.c vector.c vector.h HW2.tar
a. This command is syntactically invalid. You cannot provide the name of the tar file as the final
argument of the command.
b. Only the C files (not the header files) are added into an archive file called HW2.tar. Header file
contents can be inferred from C files, so they do not need to go into tar files.
c. The contents of main.c is overwritten. main.c is now a tar file in the computer’s mind and
contains vector.c and vector.h.
d. An archive file called HW2.tar is created. This file contained uncompressed versions of main.c,
vector.c, and vector.h.
c. The contents of main.c is overwritten. main.c is now a tar file in the computer’s mind and
contains vector.c and vector.h.
You are a member of a shared computer, and you have uploaded a file called clients.xlsx that you
need other people on the computer with the same classification as you to be able to see and modify.
Which command will grant the necessary permissions? You may assume you are in the directory with
the file.
a. pmod clients g+rw
b. chmod g+rw clients
c. pmod group clients.xlsx +rw
d. chmod g+rw clients.xlsx
d. chmod g+rw clients.xlsx
Which of the following statements about dynamic memory is FALSE?
a. Dynamic allocations have space reserved for them in memory at runtime.
b. Dynamic memory is garbage collected if we lose all references to it.
c. We can grow or shrink the size of a dynamically allocated array at will.
d. Dynamic memory is used to keep items from disappearing after function calls end.
b. Dynamic memory is garbage collected if we lose all references to it.
How many bytes of memory does the following allocation reserve?
double* arr = calloc(10, sizeof(double));
a. 80
b. 40
c. 20
d. 10
a. 80
Which step in the compilation process produces assembly code?
a. assembler
b. preprocessor
c. linker
d. compiler
d. compiler
Examine the code below. In what situation would input be NULL?
FILE* input = fopen(“my_input_file.txt”, “r”);
a. If my_input_file.txt does not exist anywhere on the computer.
b. If my_input_file.txt is an empty file.
c. If my_input_file.txt does not exist in the current working directory.
d. If my_input_file.txt has both read and execute permissions.
c. If my_input_file.txt does not exist in the current working directory.
Answer questions 11-13 below using the following directory structure (from HW1). You are
just inside your food_court directory. Assume you are on rlogin. If you were to run the ls
command, you would see drinks and food.
food_court/ <– YOU ARE HERE
|– drinks
| >– coffee.txt
| >– smoothie.txt
| >– soda.txt
|– food
|– mains
| >– burger.txt
| >– pizza.txt
|– sides
>– fries.txt
>– salad.txt
>– smoothie.txt
- Which of the following will create a file called taco.txt in the mains directory from your current
location?
a. mk taco.txt food/mains
b. touch ./food/mains/taco.txt
c. touch taco.txt ./food/mains/
d. touch /food_court/food/mains/taco.txt
b. touch ./food/mains/taco.txt
Answer questions 11-13 below using the following directory structure (from HW1). You are
just inside your food_court directory. Assume you are on rlogin. If you were to run the ls
command, you would see drinks and food.
food_court/ <– YOU ARE HERE
|– drinks
| >– coffee.txt
| >– smoothie.txt
| >– soda.txt
|– food
|– mains
| >– burger.txt
| >– pizza.txt
|– sides
>– fries.txt
>– salad.txt
>– smoothie.txt
- You decide to remove the mains directory. You run this command:
rmdir ./food/mains/
The command fails. What is the most likely reason the command failed?
a. The directory contains files. It must be empty to remove it in Linux.
b. rmdir will only work with an absolute path, not a relative path.
c. rmdir must be called from within the directory you want to remove.
d. The command does not know if you want to remove food or mains.
a. The directory contains files. It must be empty to remove it in Linux.
Answer questions 11-13 below using the following directory structure (from HW1). You are
just inside your food_court directory. Assume you are on rlogin. If you were to run the ls
command, you would see drinks and food.
food_court/ <– YOU ARE HERE
|– drinks
| >– smoothie.txt
| >– soda.txt
|– food
|– mains
| >– burger.txt
| >– pizza.txt
|– sides
>– fries.txt
>– salad.txt
>– smoothie.txt
- The menu is getting a bit of a rewrite. coffee.txt needs to be renamed to latte.txt. Which of the
following commands will accomplish the menu modification? (Assume this command will be run from
the drinks directory.)
a. rn coffee.txt latte.txt
b. rn latte.txt coffee.txt
c. mv latte.txt coffee.txt
d. mv coffee.txt latte.txt
d. mv coffee.txt latte.txt
You are working with a text file that contains the following text:
16,Senger5Cao
You do not care about anything in that file except the two numbers, but those two numbers could be
anything. How would you properly format an fscanf statement to read those 2 numbers into int x and
int y?
a. fscanf(in, “%x,Senger%yCao\n”);
b. fscanf(in, “%d,Senger%dCao\n”, &x, &y);
c. fscanf(in, “%d %d\n”, &x, &y);
d. fscanf(in, “%d,Senger%dCao\n”, x, y);
b. fscanf(in, “%d,Senger%dCao\n”, &x, &y);
Examine the following code. Assume function() is called from main() at some point, and assume
that all necessary include statements are at the top of the file.
void function()
{
for (int i; i < 10; i++)
{
printf(“%d “, (i * i) + 1);
}
}
When this code is compiled and run, what is displayed on the terminal?
a. 1 2 5 10 17 26 37 50 65 82
b.
1
2
5
10
17
26
37
50
65
82
c. indeterminate
d. %d %d %d %d %d %d %d %d %d %d
4
c. indeterminate