Operator Precedence Rules in Ruby

Description

Think you know operator precedence rules? Test yourself on operator precedence rules in ruby with this short quiz.
Domhnall Murphy
Quiz by Domhnall Murphy, updated more than 1 year ago
Domhnall Murphy
Created by Domhnall Murphy over 2 years ago
2449
0
1 2 3 4 5 (0)

Resource summary

Question 1

Question
What is the output from the following ruby statement: puts (1 + 2 * 2)
Answer
  • 5
  • 6
  • 3
  • 4

Question 2

Question
What is the output from the following ruby statement: puts (4 * 6 / 2 * 2)
Answer
  • 6
  • 24
  • 3
  • 0

Question 3

Question
What is the output from the following ruby expression: puts (4 / 2 * 2 + 2 / 2)
Answer
  • 4
  • 2
  • 3
  • 5

Question 4

Question
What is the output from the following ruby statement: puts (5 + 10 % 3 + 6 / 2)
Answer
  • 9
  • 3
  • 512
  • 612

Question 5

Question
What is the output from the following ruby statement: puts (4 * 2 ** 2 * 2)
Answer
  • 32
  • 16
  • 128
  • 64

Question 6

Question
What is the output from the final ruby statement: c = 3 d = 4 puts (c or d == 7)
Answer
  • 3
  • true
  • false
  • 1

Question 7

Question
What is the output of the last ruby statement x = 5 && 4 puts x
Answer
  • true
  • false
  • 5
  • 4

Question 8

Question
What is the output of the last ruby statement x = 5 and 4 puts x
Answer
  • true
  • false
  • 5
  • 4

Question 9

Question
What is the output from the final ruby statement: a = false b = true ! a || b = false puts b
Answer
  • true
  • false
  • 0
  • 1

Question 10

Question
What is the output from the following ruby statement puts (13 & 10 << 1)
Answer
  • 4
  • 16
  • 5
  • 8

Question 11

Question
What is the output from the final ruby statement a = false b = true puts (a && b ? 'foo' : 'bar')
Answer
  • true
  • false
  • foo
  • bar

Question 12

Question
What is the output from the final ruby statement a = false b = true puts (a and b ? 'foo' : 'bar')
Answer
  • true
  • false
  • foo
  • bar
Show full summary Hide full summary

0 comments

There are no comments, be the first and leave one below:

Similar

Historical Development of Computer Languages
Shannon Anderson-Rush
Useful String Methods
Shannon Anderson-Rush
Flvs foundations of programming dba 2
mariaha vassar
Python Quiz
karljmurphy
computer systems and programming quiz
Molly Batch
Think Python
tsilvo2001
C Programming
Miki Rana
Generations of Programming Languages
Balikkoftesi
Mapa Conceptual - Arreglos
ciroivan94