All multiple choice questions are equally weighted You can generally assume that code shown in the questions is intended to be syntactically correct unless something in the question or one of the answers suggests otherwise 1 What is printed by the following program fragment int p test int a int b int d d a b a d b d return d int main void int a 1 b 2 c 3 d 4 c p test a b printf d d d d a b c d A B C D E 2 1234 1 1 1 1 1 1 1 4 1 1 1 4 1 1 1 1 What does the following code print Assume the program compiles without error Trick question Note the semicolon at the end of the second line int i for i 1 i 10 i i 1 printf d i A B C D E 3 the numbers 1 through 10 the number 1 only the number 10 only the number 11 only can t tell because i is not initialized What is the output of the following program fragment x 6 y 5 z 1 if x y y z printf Yellow else printf Green A B C D E No output because the printf doesn t have a placeholder Can t tell because x y y z is not legal C is a syntax error Yellow Green YellowGreen Page 2 4 What is the output of the following program include stdio h void F int a int b int c c a a b b c int main void int a b c a 5 b 4 c 10 F a b printf a d b d c d a b c return 0 A B C D E 5 a 1 b 5 c 10 a 5 b 4 c 10 a 5 b 4 c 4 a 4 b 5 c 5 a 21 b 22 c 23 Which of these three program fragments have the same output apart from spacing All variables are ints i printf 1 n2 n3 n4 n5 n6 n7 n8 n9 n ii for i 9 i 0 i j i 10 printf d n j iii i 1 while i 10 printf d n i i A B C D E i and ii ii and iii i ii and iii None have the same output i and iii Page 3 6 Consider the following program fragment double taxes 3 double total total taxes 1 taxes 2 taxes 3 line A Choose the best statement A B C D E 7 Line A is wrong because of an out of bounds error Line A is correct but for the sake of efficiency line A should be rewritten as a for loop Line A can be written more efficiently as total taxes Line A has a logic error because total is not initialized There is no logic or syntax error in line A The following program fragment has its lines numbered for reference along the left hand side The code prints a figure that looks like this 1 2 3 4 5 6 7 8 define SIZE 4 int col int row 1 while row SIZE col 1 while col row printf col col 1 10 printf n 11 row row 1 Suppose we wanted the output look like this instead What changes to the code would accomplish this A B C D E 3 int row 4 4 while row 1 11 row row 1 1 define SIZE 4 5 col 4 6 while col row 3 int row 4 11 row row 1 5 col 4 Page 4 8 What values of a b and c respectively make the following condition evaluate to true or 1 b a c b I 0 0 0 II 1 1 1 III 1 1 0 IV 1 0 0 A B C D E 9 I II and III only II and IV only IV only There are some combinations of values which make it true but none are listed among the choices There exists no combination of values make this expression true What is true about compound statements in C A A compound statement must contain at least one statement B A compound statement cannot contain another compound statement C A compound statement cannot contain any function calls A B C D E A only B only C only None of A B or C All of A B and C 10 If x an integer variable has the value 1 at the start of the following code fragment what is its value at the end if x 0 x 3 x x 1 if x 2 x x 2 0 x x 1 else x x 3 A B C D E 0 1 2 3 4 11 Which of the following does not itself cause a change in the sequential control flow of a program in execution A B C D E assignment statement function call return statement switch statement if statement Page 5 12 A sentinel in programming as we have used it is A B C D E a statement which checks for an error a special value on input the vertical bar character used in the or operation a peer or colleague who reads a program to check for errors any warning or error when a program is compiled 13 Among the choices offered which condition is equivalent to the following assume the variables are chars answer y option q A B C D E answer n option q answer n option q answer y option q answer y option q answer y option q 14 Suppose that the function Snipe begins void Snipe int f double d char ch int i j double x y char a b What are the types of the three expressions int ch i d f f i A B C D E int double int int illegal int char double illegal illegal illegal int int illegal int Page 6 15 The function AddOne can be used to increment a variable The code for AddOne is void AddOne int x x x 1 Which of the following is a correct implementation of the AddTwo function which adds two to a variable A B C D E void AddTwo int y AddOne y AddOne y void AddTwo int y AddOne y AddOne y void AddTwo int y AddOne y AddOne y void AddTwo int y y y 2 void AddTwo int y int temp temp y AddOne temp AddOne temp 16 Here is an incomplete truth table for P Q If the last column were filled in how many T s would that column contain P Q P Q T T T F F T F F A B C D E 0 1 2 3 4 Page 7 17 Worth 2 M C questions Write the function getIntInRange which is intended to return a value typed in by the user The function will make sure that the user types in a value that is within a given range of integers getIntInRange takes …
View Full Document
Unlocking...