Multiple-Choice Quiz 1 1. Which of the following does a debugger(调试器) do? Analyze the source code to find programming errors. (这是编译器的事) Decode machine code generated by a compiler. (将编译器生成的代码解码) 如 for (i = 0; i < 4; i++) { sum += array[i]; } The Visual C++ compiler will translate that loop into the following machine code, which is directly executed by the hardware: 11000111010001011111101000000000000000000000000000000000 11101011000010011000101101000101111111001000001111000000 00000001100010010100010111111100100000110111110111111100 00000100011111010001001010001011010011011111110010001011 01010101111110000000001100010100100011011101100000100101 01000010000000001000100101010101111110001110101111011111 Stop execution of a program. (a) I and III only (b) III only (c) I, II, and III. (d) II and III only Correct answer is (d) Feedback: See section 1.1.3 of the course notes. -------------------------------------------------------------------------------2. The machine code generated from source code by a compiler (a) can be easily inspected to check the correctness of the compiler (b) executes more quickly than the source code (c) associates variable values with their names (d) does not preserve(维持,保存) all the information given in the source code (被优化了一些 代码)(由编译器生成的代码会被优化) Correct answer is (d) Feedback: See section 1.1.3 of the course notes. -------------------------------------------------------------------------------3. In Visual C++, a Win32 Console Application is (a) the status window of the Visual C++ environment (b) built by using sophisticated "Application Wizards" (c) a program that is able to control the operating system of a windows computer (d) the simplest type of application Visual C++ can generate (Win32 控制台应用程序是 VC++ 能生成的最简单的应用程序) Correct answer is (d) Feedback: See section 1.2.1 of the course notes. -------------------------------------------------------------------------------- 4. When debugging using Visual C++, which of the following are possible through the Watch window? The program's execution can be stopped. (watch 中没有这个功能) The value of an arbitrary C expression can be calculated. The value of a program variable can be set. (!) (Watch 可以设置监视器来计算任意表达式的值,可以设定变量的值,但是不能停止程序的 执行) (卡耐基上原话)You can also modify the current value of a variable while the program is running, by displaying the value using the Variable or Watch windows, or both, and double-clicking on the value. (a) II and III only (b) II only (c) III only (d) I, II, and III. Correct answer is (a) Feedback: See section 1.2.3 of the course notes. -------------------------------------------------------------------------------5. Consider the program given below. #include int callee(void) { int count = 5; printf("%d ", (int) &count); (打出来的是 callee 中局部变量 count 的地址) return count; } int main (int argc, char *argv[]) { int count = 4; count = callee(); printf("%d ", (int) &count); (打出来的是 main 中局部变量 count 的地址) return 0; } Which of the following describes the output of the program? (a) 5 and 4 are printed, in that order on the same line. (b) Two different integers are printed, and the value of neither can be determined from the information given. (c) One integer is printed twice, and its value cannot be determined from the information given. (d) 5 is printed twice on the same line. Correct answer is (b) Feedback: See section 1.4.1 of the course notes. -------------------------------------------------------------------------------6. Consider the following program. int i; int * jp = &i; int main(int i, char * argv[]) { printf("%d %d\n", (int) &i, (int) jp); (打出来的是 main 中局部变量 i 的地址,(int) jp 是全局 变量 i 的地址) } Which of the following describes what it prints? (a) two integers that are exactly the same (b) two values, one 4 greater than the other (c) nothing: it will not compile because it is ambiguous (d) two very different integers Correct answer is (d) Feedback: See section 1.4.1 of the course notes. ------------------------------------------------------------------------------7. What is printed as a result of execution of the following program? #include <stdio.h> void callee(int * count) {(这里 count 是一个指针,指向 main 中的 int 型 count 变量) (*count)++; } int main (int argc, char *argv[]) { int count = 4; callee(&count); printf("%d", count); return 0; } (a) 8 (b) It cannot be determined from the information given. (c) 4 (d) 5 Correct answer is (d) Feedback: See section 1.4.1 of the course notes. -------------------------------------------------------------------------------8. What does the following program print? void callee(int * count) { count++;(count 只是 main 中 count 的地址) } int main (int argc, char *argv[]) { int count = 4; callee(&count); printf("%d", count); return 0; } (a) 5 (b) 8 (c) 4 (d) cannot be determined from the information given. Correct answer is (c) Feedback: See section 1.4.1 of the course notes. -------------------------------------------------------------------------------9. In a computer in which both addresses and integers are 32 bits wide, how many bytes of memory will the compiler allocate as a result of the following pointer declaration? int * pointer; (a) 4(int 型的指针变量也是 4 个字节) (b) 64 (c) 8 (d) 0 Correct answer is (a) Feedback: See section 1.3.2 of the course notes. -------------------------------------------------------------------------------10. Consider the following segment of a C program. int i = 99; int a[100]; i = a[i + 1];(这里数组越界了,其实 a[100]的地址上就是 i) Which of the following is true of the segment? (a) i will have the value of the last element of the array a at the end of any execution of the segment. (b) Execution will fail because a has the wrong size. (c) When executed, the program will be prematurely terminated by the operating system because of an illegal memory access. (d) i will have the value 99 at the end of any execution of the segment. Correct answer is (d) Feedback: See section 1.3.5 of the course notes. --------------------------------------------------------------------------11. A CPU register is a word of CPU memory that (a) is automatically loaded when a CPU instruction refers to a word of normal memory (b) is explicitly( 明 确 地 , 精 确 地 ) loaded and unloaded from normal memory by compiler-generated instructions(CPU 寄存器是根据编译器的指令精确地从内存中载入或载出 数据) (c) houses a critical variable for the duration of the execution of a program (d) records the results of periodic CPU diagnostics Correct answer is (b) Feedback: See section 1.5.3 of the course notes -------------------------------------------------------------------------------12. Which of the following computations may be performed by exactly one CPU instruction? a = 5; (只有这条语句只需一条 cpu 指令) a = b + c * 5; for (i = 0; i < 10; i += a[i++]); (a) I and II only (b) I only (c) I, II, and III (d) II only Correct answer is (b) Feedback: See section 1.5.1 of the course notes. -------------------------------------------------------------------------------13. Which of the following is a good reason (are good reasons) to equip the CPU with small amounts of fast memory? To make the design of the compiler simpler To make some CPU instructions smaller To make some CPU instructions faster (CPU 要配置一些快速的存储器,如 Register,是因为要让一些 CPU 指令更小更快执行) (a) II and III only (b) I, II, and III (c) II only (d) III only Correct answer is (a) Feedback: See section 1.5.3 of the course notes. -------------------------------------------------------------------------------14. We want the variable factorialfunc to hold the address of the first instruction of the following function: int factorial(int n) { if (n == 1) return n; return n * factorial(n -1); } How would we declare the variable? (a) int (int) * factorialfunc (b) we can't: C cannot extract the addresses of instructions. (c) int (*factorialfunc)(int); (看卡耐基上的内容,由于方法的定义是 int factorial(int n)这样的 所以这里用*factorialfunc 代替了 factorial,即类型对应) (d) factorial() * factorialfunc; Correct answer is (c) Feedback: See section 1.5.2 of the course notes. -------------------------------------------------------------------------------1. Consider the following fragment of C++ source code. String msg; unsigned int x; int y; cin >> msg >> x >> y; cout << x + y; Which of the following is (are) true regarding execution of the segment? The input statement will always take the same amount of time to execute. The output statement will always be executed immediately after the input statement. (还要算 x+y) If x and y are both positive, an integer greater than both will be printed. (还可能越界,这时候就 打不出数了) (a) none (b) II only (c) II and III only (d) I and II only Correct answer is (a) Feedback: See section 1.1.1 of the course notes. -------------------------------------------------------------------------------2. Integrated programming environments make it difficult to mix and match tools from different sources(来源). This is (IDE 中很难扩展别的工具是不好的,这样就不能让第三方开 发商来供应一些 tools,而只有一家供应的 tools 很难达到都好用) (a) bad, because all the tools will then have the same user interface (b) bad, because no single vendor(卖方,供应商) is likely to be the source of all the best tools (c) good, because it ensures compilation is not done incrementally by accident (d) good, because tools from different sources cannot be made to interact with each other Correct answer is (b) Feedback: See section 1.1.4 of the course notes. -------------------------------------------------------------------------------4. Within Visual C++, which of the following will reveal(显示,透露) the value of a variable when the program is stopped at a breakpoint? (在调试的过程中通过鼠标指着相应变量或者使用 watch 的方法可以得到变量的值) Placing the mouse pointer over the variable name in the source file window. Inserting a printf() in the program. Typing the variable name on the "Watch" window. (a) III only (b) I, II, and III (c) II and III only (d) I and III only Correct answer is (d) Feedback: See section 1.2.3 of the course notes. -------------------------------------------------------------------------------5. What does the following program print? void callee(int * count) { count++; } int main (int argc, char *argv[]) { int count = 4; callee(&count); printf("%d", count); return 0; } (a) 8 (b) cannot be determined from the information given. (c) 5 (d) 4 Correct answer is (d) Feedback: See section 1.4.1 of the course notes. -------------------------------------------------------------------------------6. What does the following program print? void callee(int * count) { (*count)++; } int main (int argc, char *argv[]) { int count = 4; callee(count); (并没有传正确类型的参数,会出错) printf("%d", count); return 0; } (a) 4 (b) 5 (c) nothing: it will not compile successfully (d) 8 Correct answer is (c) Feedback: See section 1.4.1 of the course notes. -------------------------------------------------------------------------------7. What does the following program print? int callee(int * count) { count++;(count 是个地址) return *count; } int main (int argc, char *argv[]) { int count = 4; int retval; retval = callee(&count); printf("%d", retval); return 0; } (a) cannot be determined from the information given. (b) 4 (c) 8 (d) 5 Correct answer is (a) Feedback: See section 1.4.1 of the course notes. -------------------------------------------------------------------------------8. When executing a function callee(), which of the following are true regarding the value of the frame pointer? It marks the top of the stack frame of the function that invoked callee(). It marks the bottom of the stack frame of callee() It is the top of the stack. (当一个方法 callee()被方法 main()调用时,frame pointer 指针将指向 callee()的 stack frame 的栈底,指向 main()的 stack frame 的栈顶) (a) I only (b) II only (c) III only (d) I and II only The stack pointer holds the address where the stack ends-it is here that a new activation record will be allocated. (当前栈顶) The frame pointer holds the address where the previous activation record ends-it is to this value that the stack pointer will return when the current function returns. (当前运行方法的开始处,栈底) Correct answer is (d) Feedback: See section 1.4.2 of the course notes. -------------------------------------------------------------------------------- 9. Consider the following segment of C source code. int a = 8; int b = *&a; (先取址再取值,抵消) What is the value of variable b at the end of execution of the segment? (a) (int) &a (b) &a (c) (int) &b (d) a Correct answer is (d) Feedback: See section 1.3.2 of the course notes. -------------------------------------------------------------------------------10. In a computer in which both addresses and integers are 32 bits wide, how many bytes of memory will the compiler allocate as a result of the following pointer declaration? int * pointer; (a) 0 (b) 4 (c) 64 (d) 8 Correct answer is (b) Feedback: See section 1.3.2 of the course notes. -------------------------------------------------------------------------------11. We want the variable factorialfunc to hold the address of the first instruction of the following function: int factorial(int n) { if (n == 1) return n; return n * factorial(n -1); } How would we declare the variable? (a) factorial() * factorialfunc; (b) we can't: C cannot extract the addresses of instructions. (c) int (*factorialfunc)(int); (d) int (int) * factorialfunc Correct answer is (c) Feedback: See section 1.5.2 of the course notes. (c) -------------------------------------------------------------------------------12. Which of the following are true of the effect that optimizations (优化)have on the machine code generated by compilers? (优化后的代码更短小更快速了,但是也更难于理解和 调试) The resulting code will be faster and/or smaller. The resulting code will be clearer. The resulting code will be harder to debug. (a) I and II only (b) I only (c) I, II, and III (d) I and III only Correct answer is (d) Feedback: See section 1.5.3 of the course notes. -------------------------------------------------------------------------------13. A CPU register is a word of CPU memory that (a) records the results of periodic CPU diagnostics (b) is automatically loaded when a CPU instruction refers to a word of normal memory (c) houses a critical variable for the duration of the execution of a program (d) is explicitly loaded and unloaded from normal memory by compiler-generated instructions Correct answer is (d) Feedback: See section 1.5.3 of the course notes. -------------------------------------------------------------------------------14. Suppose that, using a tool such as the memory window of Visual C++, we found that a certain set of contiguous( 连 续 的 ) memory locations contained the 0xC605CD623A8365000000. What could these memory locations(存储单元) hold? the integer 0xC605CD623A8365000000 a string a CPU instruction (a) I and II only (b) I, II, and III (c) III only (d) I only Correct answer is (b) Feedback: See section 1.5.1 of the course notes. -------------------------------------------------------------------------------1. Consider the following fragment of C++ source code. String msg; unsigned int x; int y; cin >> msg >> x >> y; cout << x + y; Which of the following is (are) true regarding execution of the segment? The input statement will always take the same amount of time to execute. The output statement will always be executed immediately after the input statement. If x and y are both positive, an integer greater than both will be printed. (a) I and II only (b) II only (c) II and III only (d) none integer Correct answer is (d) Feedback: See section 1.1.1 of the course notes. -------------------------------------------------------------------------------2. Which of the following is able to describe a computation at the highest level of abstraction? (a) C code (b) C++ code(可以面向对象了) (c) machine code (d) logic Gates Correct answer is (b) Feedback: See section 1.1.2 of the course notes. -------------------------------------------------------------------------------3. When using a debugger to find the cause of a program's incorrect behavior, (a) the faulty code fragment must first be identified (b) it is often necessary to start the program multiple times under the debugger(在调试时常常 要启动好几次) (c) it is fastest to start by stopping the debugger long before the behavior appears (d) the program is usually executed to the point at which the behavior occurs and then executed backwards to find the cause Correct answer is (b) Feedback: See section 1.2.4 of the course notes. -------------------------------------------------------------------------------4. Within Visual C++, which of the following will reveal the value of a variable when the program is stopped at a breakpoint? Placing the mouse pointer over the variable name in the source file window. Inserting a printf() in the program. Typing the variable name on the "Watch" window. (a) III only (b) I and III only (c) I, II, and III (d) II and III only Correct answer is (b) Feedback: See section 1.2.3 of the course notes. -------------------------------------------------------------------------------5. Consider the following function. int factorial(int n) { if (n == 1) return n; return n * factorial(n - 1); } How many activation records are "popped" when it is invoked by the expression factorial(4)? (a) 5 (b) 1 (c) 0 (d) 4 Correct answer is (d) Feedback: See section 1.4.2 of the course notes. -------------------------------------------------------------------------------6. What does the following program print? void callee(int * count) { (*count)++; } int main (int argc, char *argv[]) { int count = 4; callee(count); printf("%d", count); return 0; } (a) nothing: it will not compile successfully (b) 5 (c) 4 (d) 8 Correct answer is (a) Feedback: See section 1.4.1 of the course notes. -------------------------------------------------------------------------------7. Consider the following program segment. int factorial(int * arg) { int n = *arg; if (n == 1) return n; return n * factorial(n - 1); } When the segment is executed, the variable n is allocated to (a) many addresses none of which is known to the compiler(动态分配的,所以编译器不知道) (b) just one address, and it was chosen by the compiler (c) many addresses that were chosen by the compiler (d) just one address, and it is not known to the compiler Correct answer is (a) Feedback: See section 1.4.1 of the course notes. -------------------------------------------------------------------------------8. What does the following program print? int callee(int * count) { count++; return *count; } int main (int argc, char *argv[]) { int count = 4; int retval; retval = callee(&count); printf("%d", retval); return 0; } (a) 4 (b) cannot be determined from the information given. (c) 5 (d) 8 Correct answer is (b) Feedback: See section 1.4.1 of the course notes. -------------------------------------------------------------------------------9. The Visual C++ Memory window displays (VC++的内存窗口显示内存地址和与之对应的 内容) (a) the names and values of variables in memory, interpreted as 32-bit integers no matter what the variables' types (b) the contents of memory, interpreted as 32-bit integers, without the associated variable names (c) the names and values of variables in memory, interpreted in one of several ways (d) the contents of memory, interpreted in one of several ways, without the associated variable names Correct answer is (d) Feedback: See section 1.3.3 of the course notes. -------------------------------------------------------------------------------10. Consider the following code. char a[100]; a[99] = *((char *) (((int) &a[0]) + 4)) If integers are 32 bits wide, which of the following values is equal to a[99]? (a) a[0] + 4 (b) a[3] (c) a[4] (d) the integer stored in the bytes a[4], a[5], a[6] and a[7] Correct answer is (c) Feedback: See section 1.3.5 of the course notes. -------------------------------------------------------------------------------11. Which of the following computations may be performed by exactly one CPU instruction? a = 5; a = b + c * 5; for (i = 0; i < 10; i += a[i++]); (a) I, II, and III (b) II only (c) I and II only (d) I only Correct answer is (d) Feedback: See section 1.5.1 of the course notes. -------------------------------------------------------------------------------12. How many return addresses does a C function have as a program executes? (a) two, one for each branch (b) one (c) as many as the number of times it is invoked (d) as many as the number of return statements within the function Correct answer is (c) Feedback: See section 1.5.2 of the course notes. -------------------------------------------------------------------------------14. Which of the following is a good reason (are good reasons) to equip the CPU with small amounts of fast memory? To make the design of the compiler simpler To make some CPU instructions smaller To make some CPU instructions faster (a) I, II, and III (b) II only (c) III only (d) II and III only Correct answer is (d) Feedback: See section 1.5.3 of the course notes. 1. Which of the following Visual C++ objects are contained within a "Project"? Files Visual C++ Solutions Flow charts (a) II and III only (b) I, II and III (c) II only (d) I only Correct answer is (d) Your score on this question is: 7.14 Feedback: See section 1.1.4 of the course notes. (d) -------------------------------------------------------------------------------2. Integrated programming environments make it difficult to mix and match tools from different sources. This is (a) bad, because no single vendor is likely to be the source of all the best tools (b) good, because it ensures compilation is not done incrementally by accident (c) good, because tools from different sources cannot be made to interact with each other (d) bad, because all the tools will then have the same user interface Correct answer is (a) Your score on this question is: 7.14 Feedback: See section 1.1.4 of the course notes. -------------------------------------------------------------------------------3. Which of the following must be true if a program is stopped at a specific line within the Visual C++ debugger? There is at least one breakpoint enabled. There is a breakpoint enabled on that line. There is a breakpoint enabled on the line preceding that line. (a) I and III only (b) I and II only (c) none (d) I only Correct answer is (c) Your score on this question is: 7.14 Feedback: See section 1.2.2 of the course notes. (c) -------------------------------------------------------------------------------6. What is printed as a result of execution of the following program? #include <stdio.h> void callee(int * count) { (*count)++; } int main (int argc, char *argv[]) { int count = 4; callee(&count); printf("%d", count); return 0; } (a) It cannot be determined from the information given. (b) 4 (c) 8 (d) 5 Correct answer is (d) -------------------------------------------------------------------------------7. Consider the following program. int i; int j = 1; int callee(int number) { int plusone; plusone = number + 1; return plusone; } int main (int argc, char *argv[]) { if (j == 1) return callee(i); return j; } Which of the following are allocated in the activation record immediately after the function callee() is invoked? (a) i, j and number only. (b) plusone only. (c) i only. (d) plusone and number only. (当 callee 被调用时只为 plusone 和 number 分配了空间) Correct answer is (d) Your score on this question is: 7.14 Feedback: See section 1.4.2 of the course notes. (d) -------------------------------------------------------------------------------8. At which of the following times is an activation record created? When a program starts executing. (当程序启动和方法调用时都要创建 activation record) Every time a function is invoked. When a variable is declared. (a) II only (b) III only (c) I and II only (d) II and III only Correct answer is (c) Your score on this question is: 7.14 Feedback: See section 1.4.2 of the course notes. (c) The program starts executing by calling the function main(). -------------------------------------------------------------------------------9. Consider the following code. char a[100]; a[99] = *((char *) (((int) &a[0]) + 4)) If integers are 32 bits wide, which of the following values is equal to a[99]? (a) the integer stored in the bytes a[4], a[5], a[6] and a[7] (b) a[3] (c) a[0] + 4 (d) a[4] Correct answer is (d) Your score on this question is: 7.14 Feedback: See section 1.3.5 of the course notes. (d) -------------------------------------------------------------------------------10. Consider the following code fragment. int a; int b; int main(int argc, char *argv[]) { int c; int d; ... /* some code */ } Which of the following must be true? (a) The value of *d is closer to the value of *c than to the value of *a. (b) The values of &a and &b are closer to each other than the values of &c and &d. (c) The values of *a and *b are closer to each other than the values of *c and *d. (d) The value of &d is closer to the value of &c than to the value of &a. Correct answer is (d) Your score on this question is: 7.14 Feedback: See section 1.3.1 of the course notes. -------------------------------------------------------------------------------12. Consider the following pseudo-instructions. 0x40B7D8 i = i - 1 0x40B7E0 branch-if-not-zero 0x40B7D8 Which of the following code fragments do the instructions encode? if (i != 0) i = i -1; while (--i); do { i = i - 1; } while (i); (a) I only (b) II and III only (c) III only (d) II only Correct answer is (b) Your score on this question is: 7.14 Feedback: See section 1.5.2 of the course notes. (b) -------------------------------------------------------------------------------13. A branch instruction (分支语句一般有两个选择) (a) sets the program counter to one of many possible values (b) sets the program counter to one of two possible values (c) increases the program counter by a fixed amount (d) unconditionally sets the program counter to its operand Correct answer is (b) Your score on this question is: 7.14 Feedback: See section 1.5.2 of the course notes. (b) -------------------------------------------------------------------------------5. Activation records are organized in stacks because (a) they are seldom needed during program execution. (b) stacks are simple enough for the hardware to manage.(在栈中存储,这样已经足够了) (c) functions need to access all the variables of the functions that call them. (d) stacks allow activation records to be pushed and popped in any order. Correct answer is (b) Your score on this question is: 7.14 Feedback: See section 1.4.2 of the course notes. (b) -------------------------------------------------------------------------------6. Consider the following program. int square(int * arg) { int n = * arg; return n * n; } int main (int argc, char * argv[]) { int arg = strtol(argv[1], NULL, 0); return square(arg); } When it is executed with the argument 5, the variable n is allocated to (a) many addresses neither of which are known to the compiler. (b) exactly one address chosen by the compiler. (c) many addresses chosen by the compiler. (d) exactly one address not known to the compiler. (动态分配,编译器不知道地址) Correct answer is (d) Your score on this question is: 0.00 Feedback: See section 1.4.1 of the course notes. (b) -------------------------------------------------------------------------------7. Consider the following program segment. int factorial(int * arg) { int n = *arg; if (n == 1) return n; return n * factorial(n - 1); } When the segment is executed, the variable n is allocated to (a) many addresses that were chosen by the compiler (b) just one address, and it was chosen by the compiler (c) many addresses none of which is known to the compiler (d) just one address, and it is not known to the compiler Correct answer is (c) Your score on this question is: 0.00 Feedback: See section 1.4.1 of the course notes. (b) -------------------------------------------------------------------------------8. What does the following program print? int callee(int * count) { count++; return *count; } int main (int argc, char *argv[]) { int count = 4; int retval; retval = callee(&count); printf("%d", retval); return 0; } (a) 8 (b) 4 (c) cannot be determined from the information given. (d) 5 Correct answer is (c) Your score on this question is: 7.14 Feedback: See section 1.4.1 of the course notes. (c) -------------------------------------------------------------------------------9. Consider the following segment of C source code. int a = 8; int b = *&a; What is the value of variable b at the end of execution of the segment? (a) (int) &b (b) &a (c) a (d) (int) &a Correct answer is (c) Your score on this question is: 0.00 Feedback: See section 1.3.2 of the course notes. (d) ------------------------------------------------------------------------------12. A jump instruction (a) changes the program counter only if its operand is equal to zero (b) unconditionally sets the program counter to its operand(jump 指令无条件的将 PC 设置到它 的操作数) (c) increases the program counter (d) changes a pointer to point to the next element of an array Correct answer is (b) Your score on this question is: 7.14 Feedback: See section 1.5.2 of the course notes. (b) ------------------------------------------------------------------------------14. How many return addresses does a C function have as a program executes? (a) one (b) as many as the number of times it is invoked (c) as many as the number of return statements within the function (d) two, one for each branch Correct answer is (b) Your score on this question is: 7.14 Feedback: See section 1.5.2 of the course notes. (b) 1. The machine code generated from source code by a compiler (a) does not preserve all the information given in the source code (b) can be easily inspected to check the correctness of the compiler (c) executes more quickly than the source code (d) associates variable values with their names Correct answer is (a) Your score on this question is: 7.14 Feedback: See section 1.1.3 of the course notes. (a) -------------------------------------------------------------------------------3. When debugging using Visual C++, which of the following are possible through the Watch window? The program's execution can be stopped. The value of an arbitrary C expression can be calculated. The value of a program variable can be set. (a) II only (b) III only (c) II and III only (d) I, II, and III. Correct answer is (c) -------------------------------------------------------------------------------5. Activation records are organized in stacks because (a) functions need to access all the variables of the functions that call them. (b) they are seldom needed during program execution. (c) stacks allow activation records to be pushed and popped in any order. (d) stacks are simple enough for the hardware to manage. Correct answer is (d) Your score on this question is: 7.14 Feedback: See section 1.4.2 of the course notes. (d) -------------------------------------------------------------------------6. Consider the following program. int i; int * jp = &i; int main(int i, char * argv[]) { printf("%d %d\n", (int) &i, (int) jp); } Which of the following describes what it prints? (a) nothing: it will not compile because it is ambiguous (b) two values, one 4 greater than the other (c) two very different integers (d) two integers that are exactly the same Correct answer is (c) Your score on this question is: 7.14 Feedback: See section 1.4.1 of the course notes. (c) -------------------------------------------------------------------------------8. What does the following program print? void callee(int * count) { count++; } int main (int argc, char *argv[]) { int count = 4; callee(&count); printf("%d", count); return 0; } (a) 5 (b) cannot be determined from the information given. (c) 4 (d) 8 Correct answer is (c) Your score on this question is: 7.14 Feedback: See section 1.4.1 of the course notes. (c) -------------------------------------------------------------------------------9. In a computer in which both addresses and integers are 32 bits wide, how many bytes of memory will the compiler allocate for following code fragment? int a; int * b = &a; (a) 32 (b) 4 (c) 0 (d) 8 Correct answer is (d) Your score on this question is: 7.14 Feedback: See section 1.3.2 of the course notes. (d) -------------------------------------------------------------------------------10. The Visual C++ Memory window displays (a) the names and values of variables in memory, interpreted as 32-bit integers no matter what the variables' types (b) the names and values of variables in memory, interpreted in one of several ways (c) the contents of memory, interpreted as 32-bit integers, without the associated variable names (d) the contents of memory, interpreted in one of several ways, without the associated variable names Correct answer is (d) Your score on this question is: 7.14 Feedback: See section 1.3.3 of the course notes. (d) -------------------------------------------------------------------------------11. How many return addresses does a C function have as a program executes? (a) two, one for each branch (b) as many as the number of times it is invoked (c) one (d) as many as the number of return statements within the function Correct answer is (b) Your score on this question is: 7.14 Feedback: See section 1.5.2 of the course notes. (b) -------------------------------------------------------------------------------12. A jump instruction (a) unconditionally sets the program counter to its operand (b) changes the program counter only if its operand is equal to zero (c) changes a pointer to point to the next element of an array (d) increases the program counter Correct answer is (a) Your score on this question is: 7.14 13. The program counter contains (a) the amount of memory a program is currently using (b) the number of CPU instructions a program has executed so far (c) the address of the CPU instruction that is about to be executed (d) the number of times a program has been executed Correct answer is (c) Your score on this question is: 7.14 Feedback: See section 1.5.2 of the course notes.