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.

pHqghUme
555

pHqghUme
555

pHqghUme
555

pHqghUme
-1 OR 2+817-817-1=0+0+0+1 --

pHqghUme
-1 OR 3+817-817-1=0+0+0+1 --

pHqghUme
-1 OR 3*2<(0+5+817-817) --

pHqghUme
-1 OR 3*2>(0+5+817-817) --

pHqghUme
-1 OR 2+180-180-1=0+0+0+1

pHqghUme
-1 OR 3+180-180-1=0+0+0+1

pHqghUme
-1 OR 3*2<(0+5+180-180)

pHqghUme
-1 OR 3*2>(0+5+180-180)

pHqghUme
-1' OR 2+851-851-1=0+0+0+1 --

pHqghUme
-1' OR 3+851-851-1=0+0+0+1 --

pHqghUme
-1' OR 3*2<(0+5+851-851) --

pHqghUme
-1' OR 3*2>(0+5+851-851) --

pHqghUme
-1' OR 2+158-158-1=0+0+0+1 or 'jR2emjcX'='

pHqghUme
-1' OR 3+158-158-1=0+0+0+1 or 'jR2emjcX'='

pHqghUme
-1' OR 3*2<(0+5+158-158) or 'jR2emjcX'='

pHqghUme
-1' OR 3*2>(0+5+158-158) or 'jR2emjcX'='

pHqghUme
-1" OR 2+780-780-1=0+0+0+1 --

pHqghUme
-1" OR 3+780-780-1=0+0+0+1 --

pHqghUme
-1" OR 3*2<(0+5+780-780) --

pHqghUme
-1" OR 3*2>(0+5+780-780) --

pHqghUme
if(now()=sysdate(),sleep(15),0)

pHqghUme
0'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z

pHqghUme
0"XOR(if(now()=sysdate(),sleep(15),0))XOR"Z

pHqghUme
(select(0)from(select(sleep(15)))v)/*'+(select(0)from(select(sleep(15)))v)+'"+(select(0)from(select(sleep(15)))v)+"*/

pHqghUme
-1; waitfor delay '0:0:15' --

pHqghUme
-1); waitfor delay '0:0:15' --

pHqghUme
1 waitfor delay '0:0:15' --

pHqghUme
doQwQEfb'; waitfor delay '0:0:15' --

pHqghUme
-5 OR 87=(SELECT 87 FROM PG_SLEEP(15))--

pHqghUme
-5) OR 391=(SELECT 391 FROM PG_SLEEP(15))--

pHqghUme
-1)) OR 937=(SELECT 937 FROM PG_SLEEP(15))--

pHqghUme
3aR0sAsF' OR 606=(SELECT 606 FROM PG_SLEEP(15))--

pHqghUme
K3k1HxY5') OR 734=(SELECT 734 FROM PG_SLEEP(15))--

pHqghUme
qhAViCd1')) OR 192=(SELECT 192 FROM PG_SLEEP(15))--

pHqghUme
555*DBMS_PIPE.RECEIVE_MESSAGE(CHR(99)||CHR(99)||CHR(99),15)

pHqghUme
555'||DBMS_PIPE.RECEIVE_MESSAGE(CHR(98)||CHR(98)||CHR(98),15)||'

pHqghUme
1'"

pHqghUme

pHqghUme
@@8vRea

pHqghUme
555

pHqghUme
555

pHqghUme
555