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. Each element in an array is associated with _______.

A. Numbers
B. Index
C. Integer
D. None of the above

View Answer


3. Array indexing in ruby starts at_________.

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

View Answer


4. Array index -1 represent ______.

A. First Element
B. Middle element
C. Last element
D. Reverse the array

View Answer


5. 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


6. Which of the following command is used to tell the size of array?

A. arraynames.size
B. arraynames.length
C. arraynames.len
D. Both A and B

View Answer


7. 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


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

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

A. 5
B. 6
C. 7
D. 8

View Answer


9. 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


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

a = [ a, b, c ] puts a.pack(a3a3a3)

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

View Answer


11. 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


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

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

A. [100, 200, 300, 400, 500]
B. 300
C. 400
D. 500

View Answer


13. 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


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

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

A. ["a","e","i","o","u"]
B. e
C. i
D. o

View Answer


15. 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


16. What is the output of the given code?

a=[[a,b]]
b=[[e,a]]
print a + b

A. [["a", "b"], ["e", "a"]].
B. [["2a", "b"], ["e"]].
C. TRUE
D. FALSE

View Answer


17. 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


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

a=[1,2,3,4,5]
b=[1,2,4,6,8]
if a[3]==b[2]
    print Equal
end

A. TRUE
B. FALSE
C. Equal
D. error

View Answer


19. 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


20. What is the output of the given code?

array1 = [[1,2,3,4,5],[0,0,0,0]]
print !array1

A. Error
B. [[1, 2, 3, 4, 5], [0, 0, 0, 0]].
C. TRUE
D. FALSE

View Answer





Discussion


* You must be logged in to add comment.