Bird
0
0

What will be the output of this Ruby code?

medium📝 Predict Output Q4 of 15
Ruby - Variables and Data Types
What will be the output of this Ruby code?
value = 5
value = "five"
puts value
A5
Bfive
CError: type mismatch
Dnil
Step-by-Step Solution
Solution:
  1. Step 1: Trace variable assignments

    First, value is assigned 5 (integer), then reassigned to "five" (string).
  2. Step 2: Determine output of puts

    puts prints the current value of value, which is "five".
  3. Final Answer:

    five -> Option B
  4. Quick Check:

    Dynamic typing allows reassignment to new types [OK]
Quick Trick: Last assigned value is printed regardless of type [OK]
Common Mistakes:
  • Expecting error due to type change
  • Thinking first assignment sticks
  • Confusing output with variable name

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes