Bird
0
0

What is the output of the following Ruby code?

medium📝 Predict Output Q13 of 15
Ruby - Hashes
What is the output of the following Ruby code?
arr = [10, 20, 30]
arr[1] = 50
puts arr.inspect
A[10, 50, 30]
B[10, 20, 30]
C[50, 20, 30]
DError
Step-by-Step Solution
Solution:
  1. Step 1: Understand array element assignment

    Assigning arr[1] = 50 changes the element at index 1 (second element) to 50.
  2. Step 2: Check the array after assignment

    Original array is [10, 20, 30]. After assignment, it becomes [10, 50, 30].
  3. Final Answer:

    [10, 50, 30] -> Option A
  4. Quick Check:

    Index 1 value changed to 50 [OK]
Quick Trick: Index 1 means second element in array [OK]
Common Mistakes:
  • Thinking index 1 is first element
  • Expecting original array unchanged
  • Confusing assignment with comparison

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes