250+ TOP MCQs on Declaring and Assigning Data to an Existing Variable and Answers

Visual Basic online quiz focuses on “Declaring and Assigning Data to an Existing Variable”.

1. An __________ statement is used to assign a value to an existing variable.
a) Arithmetic
b) Relational
c) Logical
d) Assignment

Answer: d
Clarification: An assignment statement is used to assign a value to an existing variable during run time. It is also used to add value to control property during runtime. The syntax for doing so is varName=expression, where expression can contain items such as literal constants, object properties, variables, keywords or arithmetic operators.

2. A __________ is an item of data whose values do not change while the application is running.
a) Literal constant
b) Variable
c) Auto variable
d) Extern variable

Answer: a
Clarification: A literal constant is a value of data, whose values does not change while the application is running. The values of the constants remain same throughout the application. Trying to change the value of the constant results in a syntax error. Anything can be a constant value i.e. a string, number, etc. can be constant.

3. The data type of the value assigned should be same as __________
a) Any constant defined in the application
b) The variable itself
c) Can be anything
d) Any extern defined in the application

Answer: b
Clarification: the data type of the value assigned to a variable should be same as the variable itself, i.e. assigning sting to a numeric data type will result in an error. int a =”mary” is erroneous.

4. The string literal are enclosed in __________
a) Quotation mark
b) Question mark
c) Exclamation mark
d) Dollar mark

Answer: a
Clarification: The string literal variables and constants are enclosed in quotation mark whereas the numeric literal variables and constants are not. The quotation mark differentiates a string from number and variable name.

5. While entering a numeric literal constant you need not enter a __________
a) Number
b) Special character
c) Character
d) Double variable

Answer: b
Clarification: When entering a numeric literal constant you do not enter a comma, or special characters such as dollar sign or the percentage sign. If you want to include a percentage in the assignment statement, you do so using its decimal equivalent for example you enter 0.03 instead of 3%.

6. A __________ forces a literal constant to assume a data type other than the one its form indicates.
a) Literal type constant
b) Literal type variable
c) Any literal
d) Keyword

Answer: a
Clarification: decTex=0.5D statement shows that how you convert a numeric literal constant of Double data type to decimal data type and then assign the result of a decimal variable. The D that follows 0.5 in the statement is one of the literal type characters in Visual basic. A literal type constant forces a literal constant to assume a data type other than the one its form indicates. Here D forces the double number 0.5 to assume the decimal data type.

7. A variable can store __________ value at a time.
a) Only one
b) More than one
c) Only two
d) More than two

Answer: a
Clarification: A variable can store only one value at a time. When you use an assignment statement to assign another value to the variable, the new value replaces the existing value.

8. The __________ method converts a string to a number.
a) Tryparse
b) Parse
c) Convert
d) Extern

Answer: a
Clarification: The tryparse method converts a string to a number. However, unlike the val function which always returns a double number, the tryparse method allows the programmer to specify the number’s data type. For this reason most programmer prefers to use the tryparse method. Every numeric data type in visual basic has tryparse method that converts a string to that particular data type.

9. If the tryparse method determines that the string cannot be converted to the data type, it assigns __________ to the variable.
a) -1
b) 1
c) 0
d) 2

Answer: c
Clarification: The tryparse method parses its string argument, which means it looks at each character in the string, to determine whether the string can be converted to the number of the specified data type. If the string can be converted the tryparse method, converts the string to the number and stores the number in the variable specified. If the tryparse method determines that the string cannot be converted to the appropriate data type, it assigns 0 to the variable.

10. To covert a number from one data type to another, you use the __________
a) Convert class
b) Parser
c) Literal constant
d) Object

Answer: a
Clarification: The convert class can be used in any language built in visual studio. Thus they have an advantage of the conversion function; since the conversion function can only be used in visual basic. To convert a number from one data type to another, we generally use the convert class.

Leave a Reply

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