Ruby Operator MCQ
11. Which operator is used to find exponent in ruby?
Explanation: ** is used find exponent in ruby.
12. equal? Operator is used for?
Explanation: equal? return True if the receiver and argument have the same object id.
13. Guess the operator : If Condition is true ? Then value X : Otherwise value Y?
Explanation: first evaluates an expression for a true or false value and then Ternary Operator executes one of the two given statements depending upon the result of the evaluation
14. Which operator is used to check variable and method are defined or not?
Explanation: defined? is a special operator that takes the form of a method call to determine whether or not the passed expression is defined.
15. Among the following which operator has lowest Precedence?
Explanation: ... has lowest precedence.
16. What will be the output of the given code?
Explanation: left operands value is moved left by the number of bits specified by the right operand. So after shifting 0011 by 2 times the output will be 16.
17. What will be the output of the given code?
num=(10<11)||(11===11)? (11===11.0): 0
Explanation: First check 10<11 it return true then no need to check 11===11 , condition becomes true now go to next statement 11===11.0 and it will return true.
18. What will be the output of the given code?
boolean_var = false || -20 > -18
Explanation: -20 is not greater than -18 hence the output will be false || false which is false.
19. What will be the output of the given code?
boolean_var = !true || (true || 36 != 6**2)
Explanation: 36 != 6**2 is false and true || false is true but true || !true is true hence the overall expression will evaluate to true.
20. What will the following expression evaluate to?
!true && !false
Explanation: Boolean operator && evaluates to true only when both the values are true.