Q. What will be the output of the given code?

Code:
boolean_var = 15 < 16 && 15 < 15
puts boolean_var
  • (A) TRUE
  • (B) FALSE
  • (C) Type Error
  • (D) Syntax Error
πŸ’¬ Discuss
βœ… Correct Answer: (B) FALSE
Explanation: 15<16 is true but 15<15 is false hence the overall expression will evaluate to false.

Q. What will be the output of the given code?

Code:
num=4<<2
puts num
  • (A) 4
  • (B) 8
  • (C) 16
  • (D) 32
πŸ’¬ Discuss
βœ… Correct Answer: (C) 16

Q. What will be the output of the given code?

Code:
num=4>>2
puts num
  • (A) -2
  • (B) 0
  • (C) 2
  • (D) 1
πŸ’¬ Discuss
βœ… Correct Answer: (D) 1
Explanation: left operands value is moved right by the number of bits specified by the right operand.So the answer is 1.

Q. What will be the output of the given code?

Code:
num=(10<11)||(11===11)? (11===11.0): 0
puts num
  • (A) TRUE
  • (B) FALSE
  • (C) 1
  • (D) 0
πŸ’¬ Discuss
βœ… Correct Answer: (B) FALSE
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.

Q. What will be the output of the given code?

Code:
boolean_var = 3**2 != 2**3 || true
puts boolean_var
  • (A) TRUE
  • (B) FALSE
  • (C) 1
  • (D) 0
πŸ’¬ Discuss
βœ… Correct Answer: (A) TRUE
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.

Q. What will be the output of the given code?

Code:
boolean_var = false || -20 > -18
puts boolean_var
  • (A) TRUE
  • (B) FALSE
  • (C) Type Error
  • (D) Syntax Error
πŸ’¬ Discuss
βœ… Correct Answer: (B) FALSE
Explanation: 20 is not greater than -18 hence the output will be false || false which is false.

Q. What will be the output of the given code?

Code:
boolean_var = !(100 / 10 === 10)
puts boolean_var
  • (A) TRUE
  • (B) FALSE
  • (C) Type Error
  • (D) Syntax Error
πŸ’¬ Discuss
βœ… Correct Answer: (B) FALSE
Explanation: 100/10=10 which is true but the ! before 100/10==10 will evaluate to false hence the overall expression will evaluate to false.

Q. What will be the output of the given code?

Code:
boolean_var = !true || (true || 36 != 6**2)
puts boolean_var
  • (A) TRUE
  • (B) FALSE
  • (C) Error
  • (D) None of the above
πŸ’¬ Discuss
βœ… Correct Answer: (A) TRUE
Explanation: 36 != 6**2 is false and true || false is true but true || !true is true hence the overall expression will evaluate to true.

Q. What will the following expression evaluate to?

Code:
true || false
  • (A) TRUE
  • (B) FALSE
  • (C) Syntax Error
  • (D) None of the above
πŸ’¬ Discuss
βœ… Correct Answer: (A) TRUE
Explanation: Boolean operator || evaluates to false only when both the values are false.

Q. What will the following expression evaluate to?

Code:
!true && !false
  • (A) TRUE
  • (B) FALSE
  • (C) Syntax Error
  • (D) None of the above
πŸ’¬ Discuss
βœ… Correct Answer: (B) FALSE
Explanation: Boolean operator && evaluates to true only when both the values are true.