Chapter 7

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

(answer A is acceptable also) 31. To compare the contents of two arrays, you must compare each of the ____________ in the two arrays. a. memory locations b. reference variables c. elements d. size

ANS: C

11. It is preferred practice to use a(n) ____________ as an array's size declarator. a. variable b. literal value c. named constant d. object

ANS: C

21. In C#, all arrays have a(n) ____________ that equals the number of elements in the array. a. Element property b. getSize method c. Length property d. GetBounds method

ANS: C

24. The foreach loop is designed to work with a temporary, read-only variable known as the ____________. a. loop variable b. counter variable c. iteration variable d. foreach variable

ANS: C

37. The ____________ algorithm is much more efficient than a sequential search when the data set is very large. a. random search b. quick sort c. binary search d. combinatorial search

ANS: C

45. A(n) ____________ is similar to a two-dimensional array, but the rows can have a different number of columns. a. offset array b. skewed array c. jagged array d. differential array

ANS: C

50. List objects, like arrays, are always passed to methods ____________. a. by value b. in memory c. by reference d. globally

ANS: C

52. If you know the value of the item you want to take out from a List object, but you do not know the item's index, you can use the ____________. a. - (minus) operator b. Erase method c. Remove method d. Delete method

ANS: C

54. You can call the ____________ method to insert an item at a specific index position in a List object. a. Put b. Add c. Insert d. Place

ANS: C

nswer C 7. Which one of the following statements correctly declares a reference variable named values that can be used to reference an array of int? a. int values[]; b. values[int]; c. int[] values; d. int [values];

ANS: C

12. The storage locations in an array are known as ____________. a. values b. sectors c. compartments d. elements

ANS: D

18. Of the following statements, which one correctly initializes an int array named quarters with the values 1, 2, 3, and 4? a. const int SIZE = 4; int[] quarters = new int[SIZE] { 1, 2, 3, 4 }; b. int[] quarters = new int[] { 1, 2, 3, 4 }; c. int[] quarters = { 1, 2, 3, 4 }; d. All of these statements are correct.

ANS: D

19. Look at the following code sample: const int SIZE = 10; int[] values = new int[SIZE]; for (int index = 0; index < SIZE; index++) { values[index] = index + 1; } When the loop is finished stepping through the values array, what value will be stored in values[0]? a. 10 b. 11 c. 0 d. 1

ANS: D

2. Which one of the following declaration statements is not a value type? a. decimal grossPay = 0.0m; b. int playerScore = 0; c. bool qualify = false; d. Random rand = new Random();

ANS: D

27. Because arrays are always passed ____________, a method that receives an array as an argument has access to the actual array. a. by value b. globally c. in memory d. by reference

ANS: D

35. A two-dimensional array can be thought of as having rows and columns of elements.

ANS: T

36. To access a single element in a two-dimensional array, you must use two subscripts.

ANS: T

39. To access an item that is stored in a particular row and column in a jagged array, you enclose the row and column subscripts in their own pairs of brackets..

ANS: T

41. You can optionally initialize a List object when you declare it.

ANS: T

42. Each item stored in a List has a corresponding index.

ANS: T

43. You can use subscript notation to access items in a List, just as you can with an array.

ANS: T

44. An exception will occur if a List index is less than 0 or greater than the List's Count property minus 1.

ANS: T

45. The only requirement for using a binary search is that the values in the array must be sorted in ascending or descending order.

ANS: T

5. Because variables hold only single values, they can be cumbersome in programs that process lists of data.

ANS: T

7. Arrays are reference type objects.

ANS: T

9. An array's size declarator must be a nonnegative integer value.

ANS: T

13. Each element in an array is identified by a unique number known as a(n) ____________. a. subscript b. identifier c. delimiter d. vector

ANS: A

17. When you create an array, you can optionally initialize it with a collection of values called a(n) ____________. a. initialization list b. default group c. element assembly d. starting run

ANS: A

20. When working with an array, it is important that you do not use a(n)____________. a. invalid subscript b. null value c. assignment statement d. initialization list

ANS: A

22. A(n) ____________ occurs when a loop iterates one time too many or one time too few. a. off-by-one error b. buffer overrun c. system crash d. logic error

ANS: A

19. Because the foreach loop automatically knows the number of elements in an array, you do not have to use a counter variable to control its iterations, as you would with a regular for loop.

ANS: T

20. When processing the contents of an array, the foreach loop does not provide a variable that can be used as an array subscript.

ANS: T

28. Various techniques known as ____________ have been developed to locate a specific item in a larger collection of data, such as an array. a. search engine schematics b. search algorithms c. database logic d. search protocols

ANS: B

3. A(n) ____________ is a special value that links a variable to an object. a. linker b. reference c. operator d. delimiter

ANS: B

36. To successfully ____________ the contents of two variables, we need a third variable that can serve as a temporary storage location. a. copy b. exchange c. reference d. remove

ANS: B

39. ____________ arrays, also known as 2D arrays, can hold two sets of data. a. Double-data b. Two-dimensional c. Row-column d. Duel-derivative

ANS: B

41. Look at the following code sample: const int ROWS = 2; const int COLS = 2; int[,] grid = new int[ROWS, COLS]; What is the total number of elements in the grid array? a. 2 b. 4 c. 8 d. 16

ANS: B

42. Look at the following code sample: const int ROWS = 8; const int COLS = 2; int[,] table = new int[ROWS, COLS]; Which one of the following statements stores the value 25 in the element located at the first row and second column of the table array? a. table[1, 2] = 25; b. table[0, 1] = 25; c. table[2, 1] = 25; d. table[1, 0] = 25;

ANS: B

44. Traditional two-dimensional arrays, where each row has the same number of columns, are sometime referred to as ____________. a. square arrays b. rectangular arrays c. box arrays d. 2D arrays

ANS: B

5. The ____________ creates an object in memory and returns a reference to that object. a. .NET Framework b. new operator c. = operator d. % operator

ANS: B

33. Look at the following code sample: int[] numbers = { 1, 2, 3, 4, 5 }; int highest = numbers[0]; for (int index = 1; index < numbers.Length; index++) { if (numbers[index] > highest) { highest = numbers[index]; } } What value will the highest variable contain when the loop finishes? a. 1 b. 3 c. 5 d. 15

ANS: C

35. The ____________ works like this: The smallest value in the array is located and moved to element 0. The next smallest value is located and moved to element 1. This process continues until all the elements have been placed in their proper order. a. bubble sort b. binary search c. Boolean swap d. selection sort

ANS: D

40. To declare a two-dimensional array, two ____________ are required: The first one is for the number of rows, and the second one is for the number of columns. a. reference variables b. Boolean variables c. named constants d. size declarators

ANS: D

43. Look at the following code sample: int[,] values = { { 1, 2, 3, 4 }, { 5, 6, 7, 8 } }; What is the value stored in values[1, 2]? a. 2 b. 3 c. 6 d. 7

ANS: D

47. Which one of the following statements correctly creates a List object named friendsList that holds strings? a. string friendsList = new List<string>; b. <List> friendsList(string); c. List<string> friendsList = new List<string>; d. List<string> friendsList = new List<string>();

ANS: D

48. To add items to an existing List object, use the ____________. a. += operator b. & operator c. Insert property d. Add method

ANS: D

10. The first element in an array is assigned subscript 1, the second element is assigned subscript 2, and so on.

ANS: F

15. If you provide an initialization list when declaring an array, you can leave out the size declarator, but you cannot leave out the new operator and its subsequent expression.

ANS: F

18. Because array subscripts start at 1 rather than 0, you are not as likely to perform an off-by-one error.

ANS: F

2. Memory allocated for a reference type variable is the actual location that will hold any value assigned to the variable.

ANS: F

23. When reading the contents of a file into an array, your loop should always iterate until the array is full.

ANS: F

24. Arrays are always passed by value when passed as method arguments.

ANS: F

27. An array and the variable that references it hold the same value.

ANS: F

29. You can use the == operator to compare two array reference variables and determine whether the array contents are equal.

ANS: F

30. The first step in calculating the average of all values in a numeric array is to get the total of the values, and the second step is to multiply the total by the number of elements in the array.

ANS: F

32. A search algorithm is a technique for scanning through an array and rearranging its contents in some specific order.

ANS: F

34. The primary advantage of the binary search algorithm is simplicity, but its primary disadvantage, however, is inefficiency.

ANS: F

37. Unlike a one-dimensional array, you cannot provide an initialization list for a two-dimensional array.

ANS: F

38. To sum all the elements of a two-dimensional array, you can use a pair of nested if statements to add the contents of each element to the accumulator.

ANS: F

40. The .NET Framework provides a class named Container, which can be used for storing and retrieving items.

ANS: F

6. You can store a variety of data types in an array.

ANS: F

8. The ref keyword creates an object in memory and returns a reference to the object it creates.

ANS: F

11. Because subscript numbering starts at 0, the subscript of the last element in an array is 1 less than the total number of elements in the array.

ANS: T

12. You can create an array to hold any single type of value.

ANS: T

13. The default value of a string array's elements is null.

ANS: T

14. You access the individual elements in an array using their subscripts.

ANS: T

16. When working with an array, you cannot use a subscript that is less than 0 or greater than the array size minus 1.

ANS: T

17. An array's Length property is read-only, so you cannot change its value by trying to assign a new value to Length.

ANS: T

22. To write the contents of an array to a file, open the file and use a loop to step through each array element, writing it to the file. Then close the file.

ANS: T

25. When you use either the ref or out keywords before an array parameter, the receiving method does not automatically make a local copy of the array.

ANS: T

26. The sequential search algorithm is the simplest of all array searching algorithms.

ANS: T

28. If you want to make a separate copy of an array, you must create the second array in memory and then copy the individual elements of the first array to the second. This is known as a deep copy.

ANS: T

3. Reference variables can only reference objects.

ANS: T

31. A partially filled array is normally accompanied by an integer variable that indicates the number of items actually stored in the array.

ANS: T

33. It is critical to use reference parameters in any method that must be able to change the values of the items passed to it as arguments.

ANS: T

4. Creating a reference type object typically requires the following two steps, which can optionally be coded in a single program statement: 1. Declare a reference variable. 2. Create an object and associate it with the reference variable.

ANS: T

True or False 1. Data types in C# − and the underlying .NET Framework − fall into two categories: value types and reference types.

ANS: T

15. What special value are the elements of an array of reference type objects equal to by default? a. 0 b. void c. −1 d. null

ANS: D

30. When only a reference to an object is copied rather than the object's contents, the copy is called a(n) ____________. a. shallow copy b. memory copy c. value copy d. reference copy

ANS: D

51. You can use the ____________ to take out an item at a specific index in a List. a. Delete method b. RemoveAt method c. DeleteAt method d. EraseAt method

ANS: B

9. An array's____________ indicates the number of values that the array should be able to hold. a. reference variable b. size declarator c. element d. subscript

ANS: B

1. When a(n) ____________ variable is declared, the compiler sets aside, or allocates, a chunk of memory big enough to hold the variable's data. a. reference type b. uninitialized c. value type d. dynamic type

ANS: C

26. When calling a method and passing an array variable as an argument, the variable contains a ____________ to the array. a. variable b. value c. reference d. parameter

ANS: C

32. With what value should the accumulator variable be initialized to calculate the total of all values in a numeric array? a. null b. false c. 0 d. −1

ANS: C

14. When you create a numeric array in C#, what default value is assigned to its elements? a. null b. 0 c. 255 d. −1

ANS: B

16. Which one of the following statements assigns the value 40 to the first element in an array of integers named values? a. values[-1] = 40; b. values[0] = 40; c. values[null] = 40; d. values[1] = 40;

ANS: B

21. You cannot reassign an array reference variable to a different array.

ANS: F

23. C# provides a special loop known as the ____________, that automatically iterates once for each element in the array. a. do-while loop b. foreach loop c. for loop d. while loop

ANS: B

25. ____________ is a process that runs automatically in the background from time to time, removing all unreferenced objects from memory. a. System cleanup b. Garbage collection c. Nullification d. Non-maskable Interrupt

ANS: B

29. The ____________ uses a loop to step through the elements in an an array one by one, from the first to the last. a. sequential search algorithm b. optimized search algorithm c. binary search algorithm d. basic array traversal algorithm

ANS: A

34. When you process a(n) ____________, you must process only elements containing valid items. a. partially filled array b. reference copy c. sequential search d. Boolean expression

ANS: A

38. ____________ arrays can only hold one set of data. a. One-dimensional b. Two-dimensional c. Data bound d. Classical

ANS: A

4. A variable that is used to reference an object is commonly called a(n) ____________. a. reference variable b. object variable c. class variable d. Boolean variable

ANS: A

46. A(n) ____________ is similar to an array, but it can expand at runtime. a. List object b. sequential object c. Random object d. jagged array

ANS: A

49. A List object has a(n) ____________ that holds the number of items stored in the List. a. Count property b. Total property c. Length property d. Size property

ANS: A

53. If you want to take out all items from a List object, call the ____________ method. a. Clear b. Reset c. ClearAll d. ReDim

ANS: A

6. A(n) ____________ is an object that can hold a group of values that must all be the same data type. a. matrix b. Collection c. array d. container

ANS: A

8. Which one of the following assignment statements associates an int array, that can hold 12 integers, with a reference variable named scores? a. scores = new int[12]; b. int[12] = new scores; c. int scores[12]; d. new int scores[12]

ANS: A

10. Which one of the following statements is not a valid array declaration? a. double[] parsecs = new double[10]; b. decimal[] sales = new decimal[24.5m]; c. string[] cities = new decimal[50]; d. int[] quarters = new int[4];

ANS: B


Kaugnay na mga set ng pag-aaral

Digital Marketing Principles Exam Content

View Set

Child Health Neurological Disorder Questions

View Set

Which of the following is an example of internal marketing?

View Set

Chapter 55 Burn Types/Causes MATCHING*

View Set

Tableau CRM Einstein Discovery Consultant Practice Exam

View Set

Midterm Exam 00098 Subject Verb Agreement

View Set