Visual C 2012 How To Program 5th Edition Deitel Test Bank Download
Visual C 2012 How To Program 5th Edition Deitel Test Bank Download
Bank
Download full solution manual + test bank at:
https://testbankpack.com/
CHAPTER 8—Arrays
8.1 Introduction
1. Arrays may have dimensions.
a) one
b) two
c) more than two
d) All of the above.
Answer: d
3. Arrays are data structures that may consist of data items of different types.
Answer: False. Arrays are data structures consisting of data items of the same type.
8.2 Arrays
1. The number in square brackets after an array name is the of an item.
a) value
b) position
c) size
d) None of the above.
© Copyright 1992-2014 by Deitel & Associates, Inc. and Pearson Education, Inc. All Rights Reserved.
Answer: b
© Copyright 1992-2014 by Deitel & Associates, Inc. and Pearson Education, Inc. All Rights Reserved.
a) new
b) array
c) table
d) None of the above.
Answer: a
2. Which of the following correctly declares and allocates an array of double values?
a) double A[15];
b) double() A = new double[15];
c) double[] A = new double[25];
d) All of the above.
Answer: c
4. Consider the code segment below. Which of the following statements is false?
int[] g;
g = new int[ 23 ];
a) The first statement declares an array reference.
b) The second statement creates the array.
c) g is a reference to an array of integers.
d) The value of g[ 3 ] is -1.
Answer: d
6. The number of elements in an array must be specified in brackets after the array name
in the declaration.
Answer: False. The number is never specified in the brackets after the array name in
C#.
8. Each reference in an array of references is set to null by default when the array is
allocated.
Answer: True.
© Copyright 1992-2014 by Deitel & Associates, Inc. and Pearson Education, Inc. All Rights Reserved.
a) initializer list
b) index
c) array allocation
d) None of the above.
Answer: a
3.Which of the following statements about creating arrays and initializing their elements is
false?
a) The new keyword should be used to create an array.
b) When an array is created, the number of elements must be placed in square brackets
following the type of element being stored.
c) The elements of an array of integers have a value of null before they are initialized.
d) A for loop is an excellent way to initialize the elements of an array.
Answer: c
5. Which of the following initializer lists would correctly set the elements of array n?
a) int[] n = { 1, 2, 3, 4, 5 };
b) array n[ int ] = { 1, 2, 3, 4, 5 };
c) int n[ 5 ] = { 1; 2; 3; 4; 5 };
d) int n = new int( 1, 2, 3, 4, 5 );
Answer: a
© Copyright 1992-2014 by Deitel & Associates, Inc. and Pearson Education, Inc. All Rights Reserved.
c) Using a final variable before it is initialized.
d) All of the above will produce compiler errors.
Answer: b
int result = 0;
for ( int i = 0; i < a.Length; ++i )
result += a[ i ];
int result = 0;
for ( int i = 0; i < a.Length; ++i )
{
if ( a[ i ] > 30 )
result += a[ i ];
© Copyright 1992-2014 by Deitel & Associates, Inc. and Pearson Education, Inc. All Rights Reserved.
} // end for
11.Which expression adds 1 to the element of array arrayName at index i, assuming the
array is of type int?
a) ++arrayName[ i ]
b) arrayName++[ i ]
c) arrayName[ i++ ]
d) None of the above.
Answer: a
12. Attempting to access an array element out of the bounds of an array causes a(n)
________.
a) ArrayOutOfBoundsException.
b) ArrayElementOutOfBoundsException.
c) IndexOutOfRangeException.
d) ArrayException.
Answer: c.
13. When values are provided upon declaration of an array, the new keyword is not
required.
Answer: True.
14. A constant must be initialized in the same statement where it is declared and cannot be
modified.
Answer: True.
© Copyright 1992-2014 by Deitel & Associates, Inc. and Pearson Education, Inc. All Rights Reserved.
16. C# automatically performs bounds checking to ensure the program doesn’t access data
outside the bounds of an array.
Answer: True.
2. Which function is called when an object is used where a string should be?
a) TranslateToString()
b) String()
c) ConvertToString()
d) ToString()
Answer: d
4. Suppose that class Book has been defined. Which set of statements creates an array of
Book objects?
a)
© Copyright 1992-2014 by Deitel & Associates, Inc. and Pearson Education, Inc. All Rights Reserved.
Book[] books;
books = new Book[ numberElements ];
b)
Book[] books;
books = new Book()[ numberElements ];
c)
new Book() books[];
books = new Book[ numberElements ];
d) All of the above.
Answer: a
3. The foreach repetition statement requires that you provide an array and a variable for
the purpose of:
a) preventing the structure from going past the end of the array
b) storing the value of each element that is traversed
c) acting as a counter to traverse the array
d) None of the above.
Answer: b
© Copyright 1992-2014 by Deitel & Associates, Inc. and Pearson Education, Inc. All Rights Reserved.
4. Local variables can be implicitly typed by replacing their type with keyword ______.
a) type
b) unk
c) dim
d) var
Answer: d
5. The foreach statement is preferred over the for statement when the indices of the
elements in an array will be used in the body of the repetition statement.
Answer: False. The foreach statement cannot access the indices of the elements.
© Copyright 1992-2014 by Deitel & Associates, Inc. and Pearson Education, Inc. All Rights Reserved.
b) 0, 2, 12, 6, 8
c) 0, 2, 4, 6, 5
d) 0, 2, 4, 6, 12
Answer: d
4. To pass an array argument to a method, specify the name of the array followed by empty
brackets.
Answer: False. To pass an array argument to a method, specify the name of the array
without using brackets.
6. Changes made to an entire array that has been passed to a method will not affect the
original values of the array.
Answer: False. Arrays are passed to methods by reference; therefore, changes made
within the method are direct changes to the array itself.
2. What is the method header for passing in the variable that holds a reference to an array
of Strings?
a) method_name( ref String[] array)
b) method_name( String[] ref array)
c) method_name( String[] )
d) None of the above.
Answer: a
3. Passing a reference with keyword ref gives the called method control over the passed
reference itself.
Answer: True.
5. To protect the reference of an array, it should be passed to methods with keyword val.
© Copyright 1992-2014 by Deitel & Associates, Inc. and Pearson Education, Inc. All Rights Reserved.
Answer: False. Arrays are by default passed by reference, however it’s the objects
that can be modified by the method, not the reference itself.
2. Rectangular arrays are often used to represent tables of values consisting of information
arranged in:
a) rows
b) columns
c) both a and b
d) None of the above
Answer: c
4. In rectangular array items, which expression below retrieve the value at row 3 and
column 5?
a) items[ 3. 4 ]
b) items[ 3 ][ 4 ]
c) items[ 3, 4 ]
c) None of the above.
© Copyright 1992-2014 by Deitel & Associates, Inc. and Pearson Education, Inc. All Rights Reserved.
Answer: c
6. Which statement below initializes array items to contain 3 rows and 2 columns?
a) int[,] items = { { 2, 4 }, { 6, 8 }, { 10, 12 } };
b) int[,] items = { { 2, 6, 10 }, { 4, 8, 12 } };
c) int[,] items = { 2, 4 }, { 6, 8 }, { 10, 12 };
d) int[,] items = { 2, 6, 10 }, { 4, 8, 12 };
Answer: a
7. For the array in the previous question, what is the value returned by items[ 1, 0 ].
a) 4
b) 8
c) 12
d) 6
Answer: d
8. Which of the following statements creates a multidimensional array with 3 rows, where
the first row contains 1 item, the second row contains 4 items and the final row contains 2
items?
a) int[][] items = { new int { 1, null, null, null },
new int { 2, 3, 4, 5 },
new int { 6, 7, null, null } };
b) int[][] items = { new int { 1 },
new int { 2, 3, 4, 5 },
new int { 6, 7 } };
c) int[][] items = { new int { 1 },
new int { 2, 3, 4, 5 },
new int { 6, 7 },
new int {} );
d) int[][] items = { new int { 1 },
new int { 4 },
new int { 2 } };
Answer: b
9. Which of the following sets of statements creates a multidimensional array with 3 rows,
where the first row contains 1 value, the second row contains 4 items and the final row
contains 2 items?
a)
int[][] items;
items = new int[ 3 ][ ? ];
© Copyright 1992-2014 by Deitel & Associates, Inc. and Pearson Education, Inc. All Rights Reserved.
items[ 0 ] = new int[ 1 ];
items[ 1 ] = new int[ 4 ];
items[ 2 ] = new int[ 2 ];
b)
int[][] items;
items = new int[ 3 ][ ];
items[ 0 ] = new int[ 1 ];
items[ 1 ] = new int[ 4 ];
items[ 2 ] = new int[ 2 ];
c)
int[][] items;
items = new int[ ? ][ ? ];
items[ 0 ] = new int[ 1 ];
items[ 1 ] = new int[ 4 ];
items[ 2 ] = new int[ 2 ];
d)
int[][] items;
items[ 0 ] = new int[ 1 ];
items[ 1 ] = new int[ 4 ];
items[ 2 ] = new int[ 2 ];
Answer: b
b)
© Copyright 1992-2014 by Deitel & Associates, Inc. and Pearson Education, Inc. All Rights Reserved.
int total = 0;
c)
int total = 0;
d)
int total = 0;
Answer: a
12. Multi-dimensional arrays require two or more indices to identify particular elements.
Answer: True.
13. When dealing with multi-dimensional arrays, each “row” must be the same size.
Answer: False. Each “row” in a multi-dimensional array does not have to be the same;
this functionality is described in the definition of a jagged array.
© Copyright 1992-2014 by Deitel & Associates, Inc. and Pearson Education, Inc. All Rights Reserved.
1. The foreach statement can be used only with one-dimensional arrays.
Answer: False. The foreach statement can be used with multiple-dimension arrays.
2. One could iterate through multi-dimensional arrays by using nested for loops.
Answer: True.
3. Variable-length argument lists allow you to create methods that receive an arbitrary
number of arguments.
Answer: True.
© Copyright 1992-2014 by Deitel & Associates, Inc. and Pearson Education, Inc. All Rights Reserved.
3. When an app is executed from the Command Prompt, the execution environment
passes the command-line arguments to the Main method as a string.
Answer: False. The command-line arguments are passes as a one-dimensional array
of strings.
4. Command-line arguments allow the user to pass information into an app as it begins
executing.
Answer: True.
© Copyright 1992-2014 by Deitel & Associates, Inc. and Pearson Education, Inc. All Rights Reserved.