4.8 If the value of counter is 2 or more, then the statement while (--counter >- 1) ( ? "even": "odd"); printf("%s ", counter % 2 can not be rewritten as while (--counter >- 1) ( if (counter % 2) { puts ("even"); else t puts("odd"); while (counter-1) ( if (counter % 2) { puts("even") else t puts("odd"); --counter; while (counter > 2) ( counter- if (counter % 2) { puts("even") else ( puts("odd") Chapter 4 Multiple Choice questions do ( printf("%s ", counter % 2 ? "odd" : "even"); --counter; ) while (counter >-2); 4.11 In the context of counter-controlled iteration, which of the fol- lowing is not accomplished by the control-variable initialization statement? int c 10; a) Names the control variable. b) Defines the control variable to be an integer. c) Specifies the sentinel value. d) Sets the initial value of the control varlable to 10. 4.12 Which data type should normally not be used to control a count ing loop? a) int b) float c) short d) long 415 Which of the following is not specfhed by the following code segment for (c 1; c -10; c++) a) initial value of the loop counter b) loop continuation test c) increment of the loop counter d) body statement of the loop 4.16 A programmer writes a for statement to count from 1 to 10 and explicitly mentions the 1 and the 10 in the for "header." Which rela- tional operator would probably be used in the loop-continuation test? Chapter 4 Multiple Choice questions 4.17 Using an incorrect relational operator or using an incorrect final value of a loop counter in the condition of a while or for statement is a frequent cause of errors. a) syntax b) compilation c) off-by-one d) divide-by-zero 4.21 A programmer intentionally creates a for-loop with the follow- ing for header: for (G ;) The programmer's intent was most likely to create a) a syntax error b) an infinite loop c) a logic error d) a divide-by-zero error 4.22 Which of the following is an incorrect expression to increment c by 1 in the increment expression of a for "header?" a) c + 1 b) ++c c) c++ 4.5 for Statement: Notes and Observations 4.23 If the loop-continuation condition in a for statement is initially false, (a) the body portion of the loop is not performed (b) execution proceeds with the statement following the for state- ment (c) both a and b (d) none of the above 4.26 Which statement about a correct for statement with an initiali- zation expression, a loop-continuation test, an increment expression and a loop body is false? a) The initialization expression is executed only once b) The loop-continuation test is evaluated each time through the loop c) The initialization is performed each time through the loop. d) The Increment expression is performed after the loop body 4.6 Examples Using the for Statement 4.27 The for statement header for (i 1; i 1) (d) does not evaluate correctly and should be replaced by (as y l l y Chapter 4 Multiple Choice questiong Chapter 4 Multiple Choice questions 4.44 The OR (II) operator (a) has higher precedence than the AND (&&) operator (b) stops evaluation upon finding one condition to be true (c) associates from right to left (d) is a ternary operator 4.45 The condition num !# 65 cannot be replaced by: (a) num > 65 num65 (b) I (num65) (c) num 65 (d) I (num 65) 4.47 An example of a unary operator fs (a) a relational operator (b) an assignment operator (c) an increment operator (d) a logical operator 4.49 Which statement is true? a) Operator |I has a higher precedence than operator && b) In expressions involving operator |I, making the condition that is most likely to be false the leftmost condition can often reduce execu tion time. ) The logical negation operator is a binary operator d) in expressions using operator &&, making the condition that is most likely to be false the leftmost condition can often reduce execution time. Chapter 4 Multiple Choice questions 4.51 Consider the following code, assuming that x is an integer varia- ble with an initial value of 12: if (x = 6) { printf("i", x); What is the output? (a) 6 (b) 12 (c) nothing (d) a syntax error is produced 4.53 Which statement is false? a) Any expression in C that produces a value can be used in the deci- sion portion of any control statement. b) When tested for truth or falsity, an expression that produces a nonzero value is treated as true. c) Assignments in C produce a value, namely the value that the left-hand side of the assignment had prior to the assignment. d) Operator is for comparisons; operator = is for assignment. 4.13 Secure C Programming 4.56 Which of the following statements is true? (a) Function scanf does not return a value. (b) You should never check the return value of function scanf. (c) You should check the return value of function scanf to ensure that the value it returns matches the number of items that should have been input. (d) None of the above. Chapter 4 Multiple Choice questions 4.57 Which of the following statements is true? (a) If the return value of function scanf matches the number of items that should have been input, then all the inputs are valid (b) Even if a scanf operates successfully, the values read might still be invalid. (c) When a program expects to receive input values in a specific range, you should peform range checking on the inputs to ensure that the values received are indeed in that range (eg., in a program that ex- pects grades in the range 0-100, you should check that every grade is in that range). (d) Both (b) and (c)