Visual Basic Questions and Answers – One-Dimensional Array

«
»

This set of Visual Basic Multiple Choice Questions & Answers (MCQs) focuses on “One-Dimensional Array”.

1. A simple variable, also called as a ________ variable, is one that is unrelated to any other variable in memory.
a) Changing
b) Dynamic
c) Static
d) Scalar
View Answer

Answer: d
Explanation:All variables are simple variables. A simple variable, also called a scalar variable, is one that is unrelated to any other variable in memory. At times, however, you will encounter situations in which some of the variables are related to each other.
advertisement

2. When you group together related variables, the group is referred to as _________
a) Array
b) List
c) Relation
d) Variable group
View Answer

Answer: a
Explanation:When you group together related variables, the group is referred to as an array of variables or, more simply, an array. Ex: array of all integers.

3. Using array in a program is efficient because ________
a) It shortens the program.
b) The program compiles faster
c) Number of variables are reduced.
d) Data is accessed faster
View Answer

Answer: d
Explanation: Storing data in an array increases the efficiency of a program, because data can be both stored in and retrieved from the computer’s internal memory much faster than it can be written to and read from a file on a disk.

4. Data in an array can be distinguished using _______ number.
a) Reference
b) Subscript
c) Array
d) ID
View Answer

Answer: b
Explanation:The unique number, which is always an integer, is called a subscript. The subscript indicates the variable’s position in the array and is assigned by the computer when the array is created in internal memory. The first variable in a one dimensional array is assigned a subscript of 0, the second a subscript of 1, and so on.

5. If array is of String type all values are _________ by default.
a) null
b) Null
c) 0
d) Nothing
View Answer

Answer: d
Explanation: “Nothing” is not an actual value or keyword, it means that it contains nothing. Elements in a numeric array are initialized to the number 0, and elements in a Boolean array are initialized using the Boolean keyword False. Date array elements are initialized to 12:00 AM January 1, 0001.
advertisement

6. The act of initializing array is also called as _______
a) Populating an array
b) Assigning array
c) Initializing
d) Factoring and array
View Answer

Answer: a
Explanation: Initializing an array is also called populating it. The initial values are listed in the initial-values section of the syntax, using commas to separate the values, and you enclose the list of values in braces ({}).

7. What is the value of len in the following Visual Basic code?

Dim strCities() As String = {"Bombay", "Chennai", "Ladakh", "Tamil Nadu"}
Dim len As Integer
len = strCities.Length()

a) 4
b) 0
c) 3
d) 5
View Answer

Answer: a
Explanation: Array index starts from 0.So the index of the first element is 0,the second is 1 and so on. But the length is total number of elements in array, which is 4.

8. The _________ methodreturns an integer that representsthe highest subscript in the specified dimension in the array.
a) Subscript
b) GetUpperBound
c) GetSubscript
d) SubscriptOfArray
View Answer

Answer: a
Explanation: The GetUpperBound method returns an integer that represents the highest subscript in the specified dimension in the array. When used with a one-dimensional array, the specified dimension (which appears between the parentheses after the method’s name) is always 0.
advertisement

9. What is wrong with the following statement?

Dim strCities As String = {"Bombay", "Chennai", "Ladakh", "Tamil Nadu"}

a) static keyword missing
b) array elements should be initialized using single quotes
c) array elements should be in square brackets
d) array name should be strCities()
View Answer

Answer: d
Explanation: Syntax to initialize array is Dim arrayName() As dataType = {initialValues}. We have missed the first bracket in the declaration, which is necessary requirement.

10. What is the result of the following statements?

Dim strCities() As String = {"Bombay", "Chennai", "Ladakh", "Tamil Nadu"}
strCities(2)=”Kolkata”

a) Compilation Error
b) Runtime Error
c) strCity array is {“Bombay”, “Ladakh”, “Kolkata”,”Tamil Nadu”}
d) strCity array is {“Bombay”, “Chennai”,”Kolkata”, “Tamil Nadu”}
View Answer

Answer: d
Explanation: Array index starts from 0. Thus at first strCities(2)=”Ladakh” which has been replaced by “Kolkata”. Thus in the final array we have strCity array is {“Bombay”, “Chennai”,”Kolkata”, “Tamil Nadu”}.
advertisement

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.

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!

advertisement
advertisement
advertisement
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn