COMP 211 002 Bakita Final Exam Review Session Questions UNC Chapel Hill Spring 2023 The following questions are designed to provide a challenge for you all to solve in groups Flag one of us over if you need some help Answers will be released after the session To help you know who to ask about each question they re categorized under the name of the person who wrote the question The answer key is available here S23 COMP 211 002 Final Review Session Study Questions Answers What factors must you consider when trying to optimize a program for speed Select all that apply Ryan A Function overhead B Memory calls due to page faults etc C Operation speed multiplication division etc D Word length 32 bits vs 64 bits How does virtual memory help deal with the problem of shared memory A B C D It creates more space for making multiple copies of files It creates multiple pointers to a singular physical file to share with programs It caches files in the fastest memory available It creates a queue for programs that need to access certain files When might a static variable be useful Select all that apply A Keeping track of how many times a function is called regardless of caller B Maintaining a variable s value during a for while loop without declaring it outside the loop C Making a struct functions callable without an instance of that struct D Sharing a common value between multiple instances of a struct How many bytes would the pointer state be advanced by How could we cast the pointer so that we can manually advance it by a certain number of bytes Why are memory accesses so much slower than cache accesses What does this reveal about the memory hierarchy Kenan Based on the above code how many times will the printf statement on LINE 11 be printed A 0 times since lastLookup is reset on LINE 7 every time idExist is called B 1 time since the idExist call on LINE 30 is the only time idExist is called on the same number consecutively C 1 time since lastLookup only equals the searchId on idExist call on LINE 33 D 2 times since idExist is called on a number in the list twice on LINE 31 and LINE 33 E 3 times since idExist is called on a previous called number 3 times F 3 times since idExist is called on a number not in the list three times on LINE 29 LINE30 and LINE32 G 5 times since idExist is called 5 times total What changes will occur if the static keyword on LINE 3 is removed Select all that apply A The code will not compile as idList can no longer be referenced from inside this file B C D No changes in output but idList can be referenced from another c file in the same idExist 307 will incorrectly return 0 on LINE 31 and LINE 33 idExist 5 will incorrectly return 1 on LINE 29 LINE 30 LINE 32 directory Suppose an int A is stored at virtual address 0xff987cf0 while another int B is stored at virtual address 0xff987d98 If the size of a page is 4096 bytes 2 12 then A s physical address is numerically less than B s physical address Yufan A Always true B Always false C Sometimes true sometimes false D Not enough information A B C D foo c foo o foo s foo foo foo s foo o foo c foo c foo s foo foo o foo c foo s foo o foo Which of the following is the correct ordering left to right of a file s compilation cycle Amin What is the main difference between execve and execvp A execve allows the programmer to specify the environment while execvp uses the PATH environment variable for its environment B execve terminates the current program replaces it with a new program running specified executable while execvp just directly replaces the current program C execve accepts a list for its arguments think variadic arguments while execvp takes a vector for its arguments think a variable in C of type char D execve can create a virtual environment hence the ve at the end of the function name while execvp can create a virtual pointer hence the vp at the end of the function name Which of the following scenarios is most appropriate for using both fork and exec functions together in C programming for process creation and management A When you want to create a child process that executes a different program while the parent process continues execution B When you want to create a child process that shares the same address space and code with the parent process creating a new process C When you want to replace the current process image with a new program without D When you want to pause the current process until a child process terminates Which of the following best describes the virtual address space of a running process Andrew A The virtual address space is smaller than the size of main memory B The virtual address space is equal to the size of physical memory C The virtual address space is larger than physical memory D The virtual address space is smaller than the size of disk and main memory combined E The virtual address space can be smaller or larger than physical memory F The virtual address space size is unlimited Write the positive and negative representations of the integer 12 with five binary digits Signed 5 bit representation 12 12 2 s complement 5 bit representation 12 12 Tom int arr 2 7 5 1 8 int p1 arr 4 int p2 arr 2 int x p1 p2 int y arr x printf y d y p y y Assume arr 1000 After the code is executed what will be printed A y 1 y 1008 B y 5 y 1008 C y 5 y 1012 D y 1 y 1012 fork printf Hello World n fork printf Hello World n After the code is executed how many times will Hello World get printed A 2 B 4 C 6 D 8 Kangda 1 I have a string variable named text whose address is 0x555555556781 I want to print out the fourth character of this string What command should I run a printf c n text b printf c n text 3 c printf c n text 3 d printf c n text 2 sigsetjmp will return a Always 0 b Always user defined value c 0 first and then user defined value d User defined value first and then 0 3 What does the following code do Given img stats is a stat struct containing statistics of a disk image that contains data of multiple TetrisGameState and one block is 4096 bytes for unsigned long i 0 i img stats st size i 4096 TetrisGameState game TetrisGameState img i 4 You decide to improve your tetrashell by supporting the cd command Write some pseudo code to do this Assume you are provided an executable file named …
View Full Document