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

This set of Visual Basic Multiple Choice Questions & Answers (MCQs) focuses on “Parallel & Two-dimensional Arrays”.

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
View Answer

Answer: d
Explanation: 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.

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(2)
c) strCapitals(0)
d) strCapitals(3)
View Answer

Answer: a
Explanation: 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.

3. A _______________ resembles a table.
a) One-dimensional array
b) Two-dimensional array
c) Three-dimensional array
d) N-dimensional array
View Answer

Answer: b
Explanation: 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.
advertisement
advertisement

4. We can determine number of elements in two-dimensional array by _________________
a) Multiplying number of rows and number of columns
b) Adding number of rows and number of columns
c) Multiplying number of rows and number of rows
d) Adding number of columns and number of columns
View Answer

Answer: a
Explanation: 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.

5. The _____________ in a two-dimensional array specifies the elements row and column position.
a) Superscript
b) Subscript
c) Row number
d) Column number
View Answer

Answer: b
Explanation: 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.
Note: Join free Sanfoundry classes at Telegram or Youtube

6. Each element in a two-dimensional array is identified by a unique combination of _______________
a) One subscript
b) Two subscripts
c) Three subscripts
d) Zero subscript
View Answer

Answer: b
Explanation: 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).

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
View Answer

Answer: a
Explanation: 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.
advertisement

8. To traverse two dimensional array you require ________________ loops.
a) One
b) Two
c) Three
d) Zero
View Answer

Answer: b
Explanation: 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.

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(3, 2) As Decimal
d) Dim decNums(4, 3) As Decimal
View Answer

Answer: b
Explanation: 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.
advertisement

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 500 amount with 510
c) replace the 700 amount with 710
d) replace the 800 amount with 810
View Answer

Answer: d
Explanation: 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.

Sanfoundry Global Education & Learning Series – Visual Basic.

To practice all areas of Visual Basic, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.