Quiz 2 Date Name MULTIPLE CHOICE Choose the one alternative
Solution
1. C) Post test. Because test condition of do-while loop is situated after the body of the loop.
2. D) A file must be open before any read or right.
3. B) Initialization.
4. A) 5 Because x is assigned by variable \'number\' which came with a prefix decrement operator.
5. D) Prefix increment. Incase of prefix increment, increment operator use before the variable. And it increases the value of the variable before any operation on the variable.
6. C) because the line which prints \"You failed the test\" doesn\'t comes under any if condition. So it would be printed as usual. second if condition is true so it will print \"you passed the test\".
7. C) 20 Because it will loop for 20, 19, 18...2,1 both 20 and 1 is included.
8. C) It will print 1. Because when we use conditional operator x,y,z is being treated as boolean value. As none of those contains null so anything except null is treated as true.
9. A) because x starts with value 0 and increases till less than 5 which is 4. And the \'endl\' at the end of the print statement causes line break
10. C) Because the condition (donuts !=10) is false because the value of donuts is 10 indeed. So else part is executed which adds 2 to the value of donuts
11. C) Because the condition (score > 95) is false as the value of the score is 40. So anything under if condition will not execute. As there is no curly braces after \'if\' statement so only one instruction (The instruction just after the if condition) will comes under if statement. So that line won\'t execute. Last two print instruction will execute.
12. B) Logical operator. Because logical operator takes boolean value from two expression and performs logical operations.
13. D) For loop
14. A) !
15. C) it closes the file
16. D) All of these. Because all of A, B and C can cause undesirable output
