CSCI 3061: Quiz 2
Below are a set of variables that are declared in a C program and a table representing where they are stored in memory on a 64-bit computer. The table has a bug concerning the amount of memory associated with a variable. int a = 5; int b = 7; double x = 4.5; int *ip = &a; int c; Address, Symbol, Value #1048, a, 5 #1044, b, 7 #1036, x, 4.5 #1032, ip, #1048 #1028, c, ? Which of the following describes a bug in the memory table?
The int pointer ip is allocated 4 bytes, but pointers on 64-bit systems are 8 bytes in size.
The program age.c in Problem 1 had a bug that prevented the lines You can vote, drink, and be president. Try all three at once! from being printed. What was the bug and how was it fixed?
The last case in an if/else sequence was also covered by the second-to-last case. This was fixed by adding more conditions to the second-to-last case.
ay we have the following state in memory: Address, Symbol, Value #3107, str[7], ? #3106, str[6], ? #3105, str[5], \0 #3104, str[4], o #3103, str[3], l #3102, str[2], l #3101, str[1], e #3100, str[0], h Then, we execute a line of C code that declares and defines a new pointer variable: char *cp = str; Which value is assigned to pointer cp according to the assignment and the memory table above?
#3100
In order to compile one or more C source files to an executable, which of the following must be true?
A main() function must be present and all functions used in main() must be present.
What name does the GNU C compiler give to an executable program that it compiles?
A.out
Say we have the following state in memory: Address, Symbol, Value #3107, str[7], ? #3106, str[6], ? #3105, str[5], \0 #3104, str[4], o #3103, str[3], l #3102, str[2], l #3101, str[1], e #3100, str[0], h #3092, cp, #3102 Then, we execute a line of C that declares and defines a new character variable. char cc = *cp; Which value is assigned to cc according to the assignment and memory table above?
Answer: l
When compiling with the GNU C compiler, one can pass the "Dash-o" option as in gcc -o prog name.c. Which of the following best describes what this option does?
Rather than use the default output program name, -o specifies the name that will be given to the resulting executable program, in this case prog.
Which of the following identifies and describes one of the most common output functions used in C?
printf(): It takes as arguments a format string which will substitute additional arguments, each in the specified format, before printing the string.
Say we have the following state in memory: Address, Symbol, Value #2020, arr[3], 29 #2016, arr[2], 11 #2012, arr[1], 23 #2008, arr[0], 12 #2000, arp, #2012 #1992, ptr, ? Assume ptr is an integer pointer, i.e., it is of type int *. Say we execute the following line of C code: ptr = arp + 2; Which value is assigned to ptr according to the assignment and memory table above? Assume we are running this code on an x86_64 Linux system.
ptr is assigned #2020 as the +2 is 2 units above arp and integers are 4 bytes in size.
Which of the following identifies and best describes one of the most common input functions used in C to get data typed in by a user?
scanf(): It takes a format string specifying which kind(s) of data to read along with additional arguments specifying where to store this data.