250+ TOP MCQs on Selection Structures-Logical Operators and Answers

Visual Basic Multiple Choice Questions on “Selection Structures – Logical Operators”.

1. __________ operator reverses the truth value of the operation.
a) AND
b) OR
c) NOT
d) NAND

Answer: c
Clarification: NOT operator reverses the value of the operation. True becomes false and false becomes true. For example,

The above statement returns true, if the value contained in str is false. Else it returns False.

2. __________ operator returns true, if all the sub-conditions are true.
a) AND
b) OR
c) NOT
d) NAND

Answer: a
Clarification: AND operator returns true if all the sub-conditions are true. It returns false, if any one of the sub-condition is false. For example,

The above statement returns true, if both a and b is true. If any one of a and b is false, it returns false.

3. __________ operator returns true, if any of the sub-condition is true.
a) AND
b) OR
c) NOT
d) NAND

Answer: b
Clarification: OR operator returns true, if any of the sub-condition is true. It returns false if all the sub-conditions return false. For example,

The above statement evaluates to true, if any one of a or b is true. If both a and b is false it returns false.

4. And operator checks both the sub-conditions whereas AndAlso operator does __________
a) Short-circuit evaluation
b) Short-hand evaluation
c) Short evaluation
d) Circuit evaluation

Answer: a
Clarification: And operator checks both the sub-conditions AndAlso operator does short-circuit evaluation which means in case of AndAlso operator, if any of the sub-condition is false it does not check the sub-conditions following it, but returns false.

  250+ TOP MCQs on Building the User Interface and Answers

5. And operator checks both the sub-conditions whereas OrElse operator does __________
a) Short-circuit evaluation
b) Short-hand evaluation
c) Short evaluation
d) Circuit evaluation

Answer: a
Clarification: Or operator checks both the sub-conditions, OrElse operator does short-circuit evaluation which means in case of OrELse operator, if any of the sub-condition is true it does not check the sub-conditions following it, but returns true.

6. In the below statement when true is returned?

If str=”USE” Xor strln=”USE” Then

a) When both the sub-conditions are true
b) When only one sub-condition is true
c) When both the sub-conditions are false
d) It never returns true

Answer: b
Clarification: Xor returns true when odd number of sub-conditions are true, otherwise it returns false. In the above statement, since we have two sub-conditions, Xor will return true, only when only one sub-condition is true, otherwise it will return false.

7. Which logical operator does not allow us to combine two or more conditions?
a) AND
b) OR
c) NOT
d) NAND

Answer: c
Clarification: All logical operators except NOT allows us to combine two or more conditions or sub-conditions. NOT returns true if the condition is false, thus it works on only one condition; it cannot work on multiple more than one condition or sub-conditions.

8. What will be in Msg after the following code is evaluated?

If 5*3>3^2 AndAlso True OrElse False Then
Msg=”Hi”
Else
Msg=”Bye”
Endif

a) Hi
b) Bye
c) True
d) False

Answer: a
Clarification: The condition in If statement is evaluated from left to right. When the first sub-condition is true, AndAlso checks the second sub-condition which is also true. Now OrElse check that the whole sub-condition before it is true, thus it does not evaluate the third sub-condition. Since the whole expression is true, it enters if and Msg contains Hi after the evaluation.

  250+ TOP MCQs on Multiple Alternative Selection Structures and Answers

9. What will be in Msg after the following code is evaluated?

If 3>6 AndAlso 7>4 then
   Msg=”Hi”
Else
   Msg=”Bye”
EndIf

a) Hi
b) Bye
c) True
d) False

Answer: b
Clarification: the condition in if is evaluated from left to right. When the AndAlso will see that the first sub-condition is false, it will return false, thus will not enter the If part. It will enter the else part, hence Msg will contain Bye.

10. What will be in Msg after the following code is evaluated?

If 5*3 OrElse 3^2 Then
   Msg=”Hi”
Else
   Msg=”Bye”
EndIf

a) Hi
b) Bye
c) True
d) False

Answer: a
Clarification: The first sub-condition returns a value, means it does not return zero, thus it is true. Thus OrElse will not check the second sub-condition, but will return true. Since it returns true, thus it will evaluate the If part, hence Msg will contain Hi.

Leave a Comment

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

Scroll to Top