Arrays – For Each..Next Statement - Visual Basic Questions and Answers

1.

Which of the following declares a five-element one-dimensional array?

   A.) Dim dblAmounts(4) As Double
   B.) Dim dblAmounts(5) As Double
   C.) Dim dblAmounts() As Double={3.55, 6.70, 8, 4, 2.34,1.45}
   D.) Dim dblAmounts(4) As Double = {3.55, 6.70, 8, 4, 2.34}

Answer: Option 'C'

Dim dblAmounts() As Double={3.55, 6.70, 8, 4, 2.34,1.45}

The number of elements to be declared must be given in the definition, and the elements must be declared in within the second bracket as in Dim dblAmounts() As Double={3.55, 6.70, 8, 4, 2.34,1.45}; while it is only defined in Dim dblAmounts(5) As Double; but here it is not declared.

DigitalOcean Referral Badge

2.

The intSales array is declared as follows: Dim intSales() As Integer = {10000, 12000, 900, 500, 20000}. The statement intSales(3) = intSales(3) + 10 will .

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

Answer: Option 'B'

replace the 500 amount with 510
intSales(3) is 500, and we add 10 to it, and it is replaced by 510. 500 is the fourth element, but since array index starts from 0, thus intSales(3) will contain 500. It would have been 900 if, it would have been intSales(2).

DigitalOcean Referral Badge

Arrays – For Each..Next Statement - Visual Basic Questions and Answers Download Pdf

Recent Posts