Parallel & Two-dimensional Arrays - Visual Basic Questions and Answers

1.

If the elements in two arrays are related by their subscripts, the arrays are called as ________________ arrays.

   A.) associated
   B.) coupled
   C.) matching
   D.) parallel

Answer: Option 'D'

parallel

Parallel arrays are two or more arrays whose elements are related by their position in the arrays; in other words, they are related by their subscripts. Let strIds and intPrices arrays in be parallel arrays, thus each element in the strIds array corresponds to the element located in the same position in the intPrices array. For example, the item whose product ID is BX35 [strIds(0)] has a price of $13 [intPrices(0)]. Likewise, the item whose product ID is CR20 [strIds(1)] has a price of $10 [intPrices(1)]. The same relationship is true for the remaining elements in both arrays. To determine an item’s price, you locate the item’s ID in the strIds array and then view its corresponding element in the intPrices array.

DigitalOcean Referral Badge

2.

The strStates and strCapitals arrays are parallel arrays. If Illinois is stored in the second element in the strStates array, where is its capital (Springfield) stored?

   A.) strCapitals(1)
   B.) strCapitals(1)
   C.) strCapitals(1)
   D.) strCapitals(1)

Answer: Option 'A'

strCapitals(1)
The second element of strStates is Illinois, thus is represented by strStates(1). Its capital will thus be strCapitals(1), since strStates and strCapitals are parallel arrays.

DigitalOcean Referral Badge

3.

A _______________ resembles a table.

   A.) One-dimensional array
   B.) One-dimensional array
   C.) Three-dimensional array
   D.) One-dimensional array
 

Answer: Option 'B'

One-dimensional array
The most commonly used arrays in business applications are one-dimensional and two-dimensional. You can visualize a one-dimensional array as a column of variables in memory. A two-dimensional array, on the other hand, resembles a table in that the variables (elements) are in rows and columns.

DigitalOcean Referral Badge

4.

We can determine number of elements in two-dimensional array by _________________

   A.) Multiplying number of rows and number of rows
   B.) Multiplying number of rows and number of columns
   C.) Adding number of columns and number of columns
   D.) Adding number of rows and number of columns

Answer: Option 'B'

Multiplying number of rows and number of columns
You can determine the number of elements in a two-dimensional array by multiplying the number of its rows by the number of its columns. An array that has four rows and three columns, for example, contains 12 elements.

DigitalOcean Referral Badge

5.

The _____________ in a two-dimensional array specifies the elements row and column position.

   A.) Superscript
   B.) Row number
   C.) Subscript
   D.) Column number

Answer: Option 'C'

Subscript

Each element in a two-dimensional array is identified by a unique combination of two subscripts that the computer assigns to the element when the array is created. The subscripts specify the element’s row and column positions in the array. Elements located in the first row in a two-dimensional array are assigned a row subscript of 0. Elements in the second row are assigned a row subscript of 1, and so on. Similarly, elements located in the first column in a two-dimensional array are assigned a column subscript of 0. Elements in the second column are assigned a column subscript of 1, and so on.

DigitalOcean Referral Badge

6.

Each element in a two-dimensional array is identified by a unique combination of _______________

   A.) One subscript
   B.) Two subscripts
   C.) Zero subscript
   D.) Three subscripts

Answer: Option 'B'

Two subscripts

You refer to each element in a two-dimensional array by the array’s name and the element’s row and column subscripts, with the row subscript listed first and the column subscript listed second. The subscripts are separated by a comma and specified in a set of parentheses immediately following the array name. For example, to refer to the element located in the first row, first column in a two-dimensional array named strProducts, you use strProducts(0, 0).

DigitalOcean Referral Badge

7.

The subscripts are _________ than the row and column in which the element is located.

   A.) One number less
   B.) One number more
   C.) Two number less
   D.) Two number more

Answer: Option 'A'

The subscripts are one number less than the row and column in which the element is located. This is because the row and column subscripts start at 0 rather than at 1. You will find that the last row subscript in a two-dimensional array is always one number less than the number of rows in the array. Likewise, the last column subscript is always one number less than the number of columns in the array.

DigitalOcean Referral Badge

8.

To traverse two dimensional array you require ________________ loops.

   A.) One
   B.) Two
   C.) Three
   D.) Zero

Answer: Option 'B'

You use a loop to traverse a one-dimensional array. To traverse a two-dimensional array, you typically use two loops: an outer loop and a nested loop. One of the loops keeps track of the row subscript and the other keeps track of the column subscript. You can code the loops using either the For . . . Next statement or the Do . . . Loop statement. Rather than using two loops, you also can traverse a two-dimensional array using one For Each . . . Next loop. However, recall that the instructions in a For Each . . . Next loop can only read the array values; they cannot permanently modify the values.

DigitalOcean Referral Badge

9.

Which of the following declares a two-dimensional array that has three rows and four columns?

   A.) Dim decNums(2, 3) As Decimal
   B.) Dim decNums(3, 4) As Decimal
   C.) Dim decNums(4, 3) As Decimal
   D.) Dim decNums(3, 2) As Decimal

Answer: Option 'B'

Dim decNums(3, 4) As Decimal

The first subscript gives the number of rows and the second subscript gives the number of columns. Thus Dim decNums (3, 4) As Decimal, defines a two-dimensional array with 3 rows and 4 columns.

DigitalOcean Referral Badge

10.

The intSales array is declared as follows: Dim intSales(,) As Integer = {{1000, 1200, 900, 500, 2000}, {350, 600, 700, 800, 100}}. The intSales(1, 3) = intSales(1, 3) + 10 statement will _______________

   A.) replace the 900 amount with 910
   B.) replace the 900 amount with 910
   C.) replace the 900 amount with 910
   D.) replace the 900 amount with 910

Answer: Option 'C'

replace the 900 amount with 910

The element in 2nd row, 4th column is 800. The subscript should be one less that row number and column number. Thus subscript is 1,3. Thus 800 is increased to 810 and is replaced with 810.

DigitalOcean Referral Badge

Parallel & Two-dimensional Arrays - Visual Basic Questions and Answers Download Pdf

Recent Posts