250+ TOP MCQs on Declaring and Using a Structure Variable

Visual Basic Multiple Choice Questions on “Declaring and Using a Structure Variable”.

1. Variables declared using a structure is known as ___________________
a) Variables
b) Auto variables
c) Structure variables
d) Constant variables

Answer: c
Clarification: After entering the Structure statement in the Code Editor window, you then can use the structure to declare a variable. Variables declared using a structure are often referred to as structure variables. The syntax for creating a structure variable is shown below:
{Dim | Private} structureVariableName As structureName

2. You refer to the structure variable by its ____________
a) Name
b) Data type
c) Dot operator
d) Member name

Answer: a
Clarification: In code, you refer to the entire structure variable by its name—in this case, hourly. You refer to a member variable by preceding its name with the name of the structure variable in which it is defined. You use the dot member access operator (a period) to separate the structure variable’s name from the member variable’s name.

3. You refer to the member variable by preceding its name with the name of the _________________________ in which it is defined.
a) Variable
b) Auto variable
c) Structure variable
d) Constant variable

Answer: c
Clarification: In code, you refer to the entire structure variable by its name—in this case, hourly. You refer to a member variable by preceding its name with the name of the structure variable in which it is defined. You use the dot member access operator (a period) to separate the structure variable’s name from the member variable’s name.

4. Programmers use _________________ when they need to pass a group of related variables.
a) Structure variable
b) Variable
c) Auto variable
d) Constant variable

Answer: a
Clarification: Programmers use structure variables when they need to pass a group of related items to a procedure for further processing, because it’s easier to pass one structure variable rather than many individual variables. Programmers also use structure variables to store related items in an array, even when the members have different data types.

5. Programmers use ________________ when they need to store related items in an array, even though the members have different data type.
a) Structure variable
b) Variable
c) Auto variable
d) Constant variable

Answer: a
Clarification: Programmers use structure variables when they need to pass a group of related items to a procedure for further processing, because it’s easier to pass one structure variable rather than many individual variables. Programmers also use structure variables to store related items in an array, even when the members have different data types.

6. Which statement is used to create a user-defined data type?
a) Declare
b) Define
c) Struct
d) UserType

Answer: c
Clarification: Struct is used to create a user-defined data type. It can contain members of different data type. We can access the member by using structName.memberName. You refer to a member variable by preceding its name with the name of the structure variable in which it is defined. You use the dot member access operator (a period) to separate the structure variable’s name from the member variable’s name.

7. A structure variable named address contains a member variable named strStreet. Which of the following statements assigns the string “Maple” to the member variable?
a) address&strStreet = “Maple”
b) address.strStreet = “Maple”
c) strStreet.address = “Maple”
d) strStreet&address=”Maple”

Answer: b
Clarification: We can access the member by using structName.memberName. You refer to a member variable by preceding its name with the name of the structure variable in which it is defined. You use the dot member access operator (a period) to separate the structure variable’s name from the member variable’s name.

8. An array is declared using the statement Dim inventory(4) As Product. Which of the following statements assigns the number 100 to the intQuantity member variable contained in the last array element?
a) inventory.intQuantity(4) = 100
b) inventory(4).Product.intQuantity = 100
c) inventory(3).intQuantity = 100
d) inventory(4).intQuantity=100

Answer: c
Clarification: You refer to a member variable in an array element using the syntax arrayName(subscript).memberVariableName. For example, priceList(0).strId refers to the strId member contained in the first element in the priceList array. Likewise, priceList(4).intPrice refers to the intPrice member contained in the last element in the pricelist array.

9. An application uses a structure named Employee. Which of the following statements declares a five-element array of Employee structure variables?
a) Dim workers(4) As Employee
b) Dim workers(5) As Employee
c) Dim workers As Employee(4)
d) Dim workers As Employee(5)

Answer: b
Clarification: Rather than using two parallel one-dimensional arrays to store the workers, the procedure will use a one-dimensional array of Employee structure variables. Thus Dim workers(5) As Employee declares a five-element array of Employee structure variable.

10. In most applications, the code to define a user-defined data type is entered in the form’s.
a) Declarations section
b) Definition section
c) Load event procedure
d) User-defined section

Answer: a
Clarification: you will declare the structure in the form’s Declarations section. A descriptive name for the structure would be ProductInfo. Click the blank line immediately below the Public Class frmMain clause and then press Enter to insert another blank line. Enter the following Structure statement:
Structure ProductInfo
Public strId As String
Public intPrice As Integer
End Structure

Leave a Reply

Your email address will not be published. Required fields are marked *