Select Page
Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages
Filter by Categories
nmims post
Objective Type Set
Online MCQ Assignment
Question Solution
Solved Question
Uncategorized

1. Array of arrays are called multidimensional arrays.
a) True
b) False

Answer: a [Reason:] We can put anything in an array and make it array of arrays.

2. What is the output of the given code?

```multi_d_array = [[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]]
print multi_d_array```

a) [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]].
b) [0, 0, 0, 0].
c) [0, 0, 0, 0][0, 0, 0, 0].
d) None of the mentioned

Answer: a [Reason:] Array inside array is declared and then printed.

```Output:
[[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]```

3. What is the output of the given code?

```multi_d_array = [[1,2,3,4],[0,0,0,0]]
multi_d_array.each { |x| puts "#{x}n" }```

a) [1, 2, 3, 4].
[0, 0, 0, 0].
[[1, 2, 3, 4], [0, 0, 0, 0]].
b) [0, 0, 0, 0].
c) [0, 0, 0, 0][0, 0, 0, 0].
d) None of the mentioned

Answer: a [Reason:] Array inside array is declared and then printed and .each is the iterator used.

```Output:
[1, 2, 3, 4]
[0, 0, 0, 0]
[[1, 2, 3, 4], [0, 0, 0, 0]]```

4. What is the output of the given code?

```array1 = [[1,2,3,4],[0,0,0,0]]
array2 = [[1,2,3],[0,0,0,0]]
if array1==array2
print "Equal"
else
print "Not equal"
end```

a) [[1, 2, 3, 4], [0, 0, 0, 0]].
b) Equal
c) Not equal
d) None of the mentioned

Answer: c [Reason:] Number of elements in both the arrays are not same hence they are unequal

```Output:
Not equal```

5. 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]]
if array1==array2
print "Equal"
else
print "Not equal"
end```

a) [[1, 2, 3, 4], [0, 0, 0, 0]].
b) Equal
c) Not equal
d) None of the mentioned

Answer: b [Reason:] Number of elements in both the arrays are same hence they are unequal

```Output:
Equal```

6. 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) [[2,4,6,8],[0,0,0,0]].
d) None of the mentioned

Answer: b [Reason:] By adding two arrays we mean appending those two arrays.

```Output:
[[1, 2, 3, 4], [0, 0, 0, 0], [1, 2, 3, 4], [0, 0, 0, 0]]```

7. 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) None of the mentioned

Answer: c [Reason:] We get an empty array by subtracting two arrays of same elements

```Output:
[]```

8. 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) Error

Answer: d [Reason:] We can’t directly multiply elements of array, it will show an error

```Output:
can't convert Array into Integer```

9. What is the output of the given code?

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

a) [[1, 2, 3], [0, 0, 0]].
b) [[1, 2, 3, 4], [0, 0, 0, 0], [1, 2, 3, 4], [0, 0, 0, 0]].
c) [].
d) Error

Answer: a [Reason:] Anding two arrays will give the common elements in both the arrays.

```Output:
[[1, 2, 3], [0, 0, 0]]```

10. What is the output of the given code?

```array1 = [[1,2,3,4,5],[0,0,0,0]]
array2 = [[1,2,3],[0,0,0]]
print array1 || array2```

a) [[1, 2, 3], [0, 0, 0]].
b) [[1, 2, 3, 4, 5], [0, 0, 0, 0]].
c) [].
d) Error

Answer: b [Reason:] Oring two arrays will give the maximum number common and uncommon elements in both the arrays.

```Output:
[[1, 2, 3, 4, 5], [0, 0, 0, 0]]```

11. What is the output of the given code?

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

a) [[1, 2, 3], [0, 0, 0]].
b) [[1, 2, 3, 4, 5], [0, 0, 0, 0]].
c) False
d) Error

Answer: b [Reason:] The negation of the given array is not possible hence the result is false.

```Output:
False```

12. 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) False
d) Error

```Output: