Example Problems for Exam#2 (covers chapters 5, 6, 7, 8, 9) 1. What is the final value of ? after performing the following operations int x = 24; float y = 6.0; float z = 3.0; y = x / z; ? = 2.0 * y; (a) 12 (b) 12.0 (c) 16 (d) 16.0 ANS: (d)
2. What is the lowest value of the loop counter in a for statement with the following header? for ( i = 10; i >= 1; i -=1) a) 10 b) 9 c) 1 d) 0 ANS: (d)
3. An array containing 3 columns and 4 rows is typically referred to as a ________. a) 12-element array b) 3-by-4 array c) 13-element array, because of the zero element d) 4-by-3 array ANS: (d)
4. An incorrect final value in a loop counter (increment or decrement) or an incorrect relational operator in the conditional expression of a while or for loop statement frequently causes an __________error. off-by-one 5. The function body, is represented by _____ in the following function definition: W X(Y) {Z} (a) W (b) X (c) Y (d) Z ANS: (d)
6. The following array definition int n[4] = {51, 36, 22, 45, 17}; a) is correct b) causes a syntax error because there are only four initializers and five array elements. c) causes a logic error because there are only four elements but there are five initializers. d) causes a syntax error because there are five initializers but only four array elements. ANS: (d)
7. When exit is called with EXIT_SUCCESS exit(EXIT_SUCCESS); (a) the program quits immediately without returning anything (b) the program prints an exit_success message and quits the current function (c) the implementation defined value for normal termination is returned (d) the program breaks out of a loop ANS: (c)
8. Which statement of the following is correct? (a) #define X = 3 (b) #define X 3; (c) #define X 3 (d) #define X:3 ANS: (c)