Engineering Questions with Answers - Multiple Choice Questions

MCQs on One-Dimensional Array

1 - Question

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.




2 - Question

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 - Question

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 - Question

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 - Question

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.




6 - Question

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 - Question

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 - Question

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.

 




9 - Question

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 - Question

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”}.

Get weekly updates about new MCQs and other posts by joining 18000+ community of active learners