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 are the first three lines printed by the following code int row 1 i while row 10 switch row 3 case 0 for i 1 i 4 i printf break case 1 for i 1 i 4 i printf break case 2 for i 1 i 4 i printf break default for i 1 i 4 i printf printf n row row 1 A B C D E 2 Suppose you have a program that keeps track of deposits withdrawals and interest to a bank account Inside the main function there is a variable that keeps track of the current balance in the bank account declared as follows double balance Which of the following function prototypes could NOT be a function that could be called in main to figure out the new balance and update the balance variable A B C D E double update balance double old balance double interest double amount int withdraw money double new balance double old balance double amount void add interest double old balance double new balance int days of interest double interest percent void withdrawal double old balance double amount double new balance int is overdrawn double calc moneyleft double withdraw amount double old balance Page 2 3 Just after line S of the following program executes what is the value of stop define START 10 int main void double stop start start START stop stop start line S return 0 A B C D E 4 0 0 10 10 0 unpredictable although the program will compile without error the program will have a syntax error because start is defined twice once spelled START and once as start If the program fragment below executes how many times does the word Hello get printed int i j k for i 0 i 100 i i 10 for k 0 k 5 k for j 1 j 1 j printf Hello n i i 1 A B C D E 5 10 20 50 100 Infinite What is the value of the expression x y x y y x given the following declarations int x 7 int y 3 A B C D E 3 4 5 6 7 Page 3 6 Choose the conditional expression which is true only when the value of x an int variable is even and in the range 0 to 6 A B C D E 7 x 0 x 2 x 4 x 6 x 0 x 1 x 3 x 5 x 7 x 2 1 x 0 x 6 x 2 0 x 0 x 6 x 2 x x 0 x 6 define MAXGRADES 20 int winter MAXGRADES int spring MAXGRADES int classSize i The array winter has been initialized The variable classSize contains the number of elements of winter which are used all the used elements are together without gaps starting in the 0th position of the array Which of the following code fragments will correctly copy the used elements of winter to the array spring A spring winter B for i 0 i classSize i MAXGRADES i spring i winter i C spring MAXGRADES winter MAXGRADES D spring classSize winter classSize A B C D E 8 A only B only C only D only more than one of A B C or D Among the choices given the best definition of an expression is A B C D E a series of steps which compute an answer a mathematical formula something in a program which has a value an arithmetic operation a single statement Page 4 9 What is the primary job of the Linker A B C D E To combine functions libraries etc into an executable program To translate source code into object code To find syntax errors in a program To find semantic errors in a program To convert input characters into the proper data types for the variables used for input 10 Suppose the function Snork has the following prototype int Snork char p int x int y Which of the following is a legal use of Snork assuming the declarations int i j char ch A B C D E i Snork A 10 j j Snork ch i j i Snork ch i 17 Snork ch i j None of the above 11 The setToBiggest function sets both of its input variables passed as output parameters to the value of the larger input Which of the following is the correct function body for void setToBiggest int x int y BODY A B C D E if x y y x else x y y x x y int temp temp y if x y temp x y temp x temp if x y x y if y x y x x y if y x y x Page 5 12 typedef struct char name MAX NAME 1 int id double score Student Record StudentRecord a MAX STUDENTS What are the types of the following three expressions a 0 a 5 a 0 name 0 A B C D E StudentRecord Illegal char array struct pointer name StudentRecord array StudentRecord char StudentRecord array StudentRecord Illegal StudentRecord StudentRecord char 13 typedef struct int x y Point typedef struct int color Point pos ColoredPoint MovePoint ColoredPoint cp In the function MovePoint what is the correct code to move cp to the origin of the coordinate system A B C D E cp pos x 0 cp pos y 0 cp pos x 0 cp pos y 0 cp pos x 0 cp pos y 0 cp pos x 0 cp pos y 0 cp pos 0 0 Page 6 14 void SetToQuestion char str The function SetToQuestion is supposed to set the string str to a string of all characters The length of the string is not changed For example if we have char bob 5 ABCD then the call SetToQuestion bob would make bob the string Which code correctly implements the body of SetToQuestion D int i 0 while str i 0 i i 1 str i int i 0 while str i 0 str i i i 1 int i 0 while str i str i i i 1 int i E for i 0 str i i str i int i A B C for i 0 str i i str i 0 15 char str 6 strcpy str BLACK strcpy str RED What are the values of str 3 str 4 str 5 after the two calls to strcpy A B C D E 0 0 0 0 K 0 C K 0 C K R D 0 K Page 7 16 About how many array elements need to be examined when binary search is done on an array of 65536 A B C D E 8 16 32 256 65536 17 Study this code fragment and then answer the question that follows it int find something int b int low int high int i pos pos …
View Full Document
Unlocking...