This set of Ruby Programming Multiple Choice Questions & Answers (MCQs) focuses on “Operators”.
1. Boolean opeartors are also known as logical operators.
a) True
b) False
View Answer
Explanation: Boolean operators result in boolean values like true or false.
2. Which of the following is a valid boolean operator?
a) and(&&)
b) or(||)
c) not(!)
d) All of the mentioned
View Answer
Explanation: We have three boolean operators which are and, or, not.
3. The boolean operator && only result in true when both the values are true?
a) True
b) False
View Answer
Explanation: The && operator only results in true when both the values are true rest all cases it evaluates to false.
4. What will the following expression evaluate to?
true && false
a) True
b) False
c) Error
d) None of the mentioned
View Answer
Explanation: Boolean operator && evaluates to true only when both the values are true.
5. What will be the output of the given code?
boolean_1 = 77 < 78 && 77 < 77 puts boolean_1
a) True
b) False
c) Error
d) None of the mentioned
View Answer
Explanation: 77<78 is true but 77<77 is false hence the overall expression will evaluate to false.
Output: False
6. What will the following expression evaluate to?
true || false
a) True
b) False
c) Error
d) None of the mentioned
View Answer
Explanation: Boolean operator || evaluates to true only when both the values are true or one is true and other is false.
7. What will the following expression evaluate to?
(true && false) || (!true)
a) True
b) False
c) Error
d) None of the mentioned
View Answer
Explanation: Boolean operator && evaluates to true only when both the values are true and !true means false hence the whole expression will evaluate to false.
8. What will the following expression evaluate to?
!true && !false
a) True
b) False
c) Error
d) None of the mentioned
View Answer
Explanation: Boolean operator && evaluates to true only when both the values are true.
9. What will be the output of the given code?
boolean_1 = (3 < 4 || false) && (false || true) puts boolean_1
a) True
b) False
c) Error
d) None of the mentioned
View Answer
Explanation: 3<4 is true and true or false will evaluate to true hence the overall expression will evaluate to true.
Output: True
10. What will be the output of the given code?
boolean_1 = !(3 < 4 || false) && (false || true) puts boolean_1
a) True
b) False
c) Error
d) None of the mentioned
View Answer
Explanation: 3<4 is true and true or false will evaluate to true hence the overall expression will evaluate to true but the ! used will make the whole expression evaluate to false.
Output: False
11. What will be the output of the given code?
boolean_1 = 2**3 != 3**2 || true puts boolean_1
a) True
b) False
c) Error
d) None of the mentioned
View Answer
Explanation: 2**3=8 and 3**2=9 both the values are not equal is true and true or true will evaluate to true hence the overall expression will evaluate to true.
Output: True
12. What will be the output of the given code?
boolean_1 = false || -10 > -9 puts boolean_1
a) True
b) False
c) Error
d) None of the mentioned
View Answer
Explanation: -10 is not greater than -9 hence the output will be false || false which is false.
Output: False
13. What will be the output of the given code?
boolean_1 = !(700 / 10 == 70) puts boolean_1
a) True
b) False
c) Error
d) None of the mentioned
View Answer
Explanation: 700/10=70 which is true but the ! before 700/10==70 will evaluate to false hence the overall expression will evaluate to false.
Output: False
14. What will be the output of the given code?
boolean_1 = !true puts boolean_1 boolean_2 = !true && !true puts boolean_2
a) True True
b) False False
c) True False
d) None of the mentioned
View Answer
Explanation: !true = false and !true and !true will evaluate to false.
Output: False False
15. What will be the output of the given code?
boolean_2 = !true && (!true || 100 != 5**2) puts boolean_2
a) True
b) False
c) Error
d) None of the mentioned
View Answer
Explanation: 100 != 5**2 is true and true || false is true but true and !true is false hence the overall expression will evaluate to false.
Output: False
Sanfoundry Global Education & Learning Series – Ruby Programming.
To practice all areas of Ruby Programming, here is complete set of 1000+ Multiple Choice Questions and Answers.
- Buy Ruby Programming Books
- Buy Information Technology Books
- Practice Programming MCQs
- Apply for Ruby Programming Internship
- Apply for Programming Internship