CS 1044 Homework 5 Key Spring 1999 Q Ans Reason 1 2 Valid indices run from 0 to the dimension - 1 2 1 Just trace it 3 4 1 would access index 10, which is invalid. 2 would miss index 0. 3 would miss index 0 and access index 10. 5 would miss index 0 and access invalid indices 10 and 11. 4 2 Just trace it (carefully) 5 5 arr[3] would get the value 9. 6 3 This prints the values at indices 4, 3, 2 and 1 in that order. 7 5 1 works by starting at index 0 and adding 2 to the index each time. 2 works by running i from 0 to 2499 but doubling it in the index calculation, so the indices run 0, 2, 4, etc. 3 prints two times the value for each index from 0 to 2499. 8 3 FillEm() initializes the arrays, so they must be passed by reference. 9 3 Copy() stores values into arr1[], os it must be passed by reference. 10 4 Copy() does not need to modify arr2[], so it should be passed by constant reference. 11 3 The array stores counters (ints) and it must be able to store a counter for each of 255 possible characters. 12 3 13 2 You can't assign a string to a char array except at the point of declaration. 14 3 This one prints "Ben" three times. 15 5 16 1 The extraction stops at the first whitespace character (the space after "Now"), without removing it. So the get() call will read the space. 17 2 The first call to get() here reads 4 characters ("Now "), so the second call to get will read the 'i'. 18 2 Foo() will find a mismatch at index 5 and return false. 19 1 Foo() is comparing Name1 to itself, so it will return true. 20 3 If the strings contain a mismatch at a valid index, Foo() will find that and return false. If the strings are identical up through the last valid index, then Foo() will continue comparing characters past that location.