Ruby MCQ On Array

This section focuses on "Array" in Ruby. These Multiple Choice Questions (MCQ) should be practiced to improve the Ruby skills required for various interviews (campus interviews, walk-in interviews, company interviews), placements, entrance exams and other competitive examinations.

1. Ruby arrays are ____________.

A. unordered
B. ordered
C. Both A and B
D. None of the above

View Answer


2. Array indexing in ruby starts at_________.

A. -1
B. 1
C. 0
D. Random number

View Answer


3. Which of the following is correct syntax to create an array in ruby?

A. names = Array.new
B. names = Array.new(20)
C. Both A and B
D. None of the above

View Answer


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

digits = Array(0...9)
puts #{digits}

A. [0, 1, 2, 3, 4, 5, 6, 7, 8]
B. [0, 1, 2, 3, 4, 5, 6, 7, 8]
C. [0, 1, 2, 3, 4, 5, 6, 7, 8,9]
D. [1, 2, 3, 4, 5, 6, 7, 8]

View Answer


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

n = [ 65, 66, 67 ] puts n.pack(ccc)

A. ABC
B. abc
C. BCD
D. bcd

View Answer


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

arr = [1, 2, 3, 4]
print arr

A. [1, 2, 3, 4]
B. 1234
C. error
D. Infinite Loop

View Answer


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

string_array = [a,e,i,o,u]
print string_array

A. Error
B. ["a","e","i","o","u"]
C. aeiou
D. Infinite Loop

View Answer


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

arr = [[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]]
print arr

A. [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]].
B. [0, 0, 0, 0][0, 0, 0, 0].
C. [0, 0, 0, 0].
D. error

View Answer


9. What is the output of the given code?

array = [100, 200, 300, 400, 500]
print array[5]

A. 500
B. Syntax Error
C. Nil
D. Name Error

View Answer


10. What is the output of the given code?

array1 = [[1,2,3,4],[0,0,0,0]]
array2 = [[1,2,3,4],[0,0,0,0]]
print array1-array2

A. [[1, 2, 3, 4], [0, 0, 0, 0]]
B. [[1, 2, 3, 4], [0, 0, 0, 0], [1, 2, 3, 4], [0, 0, 0, 0]]
C. []
D. Nil

View Answer





Discussion


* You must be logged in to add comment.