Bird
0
0

What is the output of this Ruby code?

medium📝 Predict Output Q13 of 15
Ruby - Arrays
What is the output of this Ruby code?
arr = [10, 20, 30]
puts arr[1]
A20
B10
C30
Dnil
Step-by-Step Solution
Solution:
  1. Step 1: Understand array indexing in Ruby

    Ruby arrays start at index 0, so arr[0] is 10, arr[1] is 20, arr[2] is 30.
  2. Step 2: Identify the value at index 1

    The code prints arr[1], which is 20.
  3. Final Answer:

    20 -> Option A
  4. Quick Check:

    arr[1] = 20 [OK]
Quick Trick: Remember Ruby arrays start at index 0 [OK]
Common Mistakes:
MISTAKES
  • Thinking array index starts at 1
  • Confusing values at different indexes
  • Expecting nil for valid index

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes