0% found this document useful (0 votes)
248 views9 pages

MCQ's On Array

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 9

MCQ’s Unit 2 - Array

1. Which of these best describes an array?

a) A data structure that shows a hierarchical behaviour


b) Container of objects of similar types
c) Arrays are immutable once initialized
d) Array is not a data structure

Answer: b
Explanation: Array contains elements only of the same type.

2. How do you initialize an array in C?

a) int arr[3] = (1,2,3);


b) int arr(3) = {1,2,3};
c) int arr[3] = {1,2,3};
d) int arr(3) = (1,2,3);

Answer: c
Explanation: This is the syntax to initialize an array in C.

3. How do you instantiate an array in Java?

a) int arr[] = new int(3);


b) int arr[];
c) int arr[] = new int[3];
d) int arr() = new int(3);

Answer: c
Explanation: Note that option b is declaration whereas option c is to
instantiate an array.
4. Which of the following is a correct way to declare a multidimensional array
in Java?

a) int[] arr;
b) int arr[[]];
c) int[][]arr;
d) int[[]] arr;

Answer: c
Explanation: The syntax to declare multidimensional array in java is either
int[][] arr; or int arr[][];

5. What is the output of the following piece of code?

public class array


{
public static void main(String args[])
{
int []arr = {1,2,3,4,5};
System.out.println(arr[2]);
System.out.println(arr[4]);
}
}
a) 3 and 5
b) 5 and 3
c) 2 and 4
d) 4 and 2

Answer: a
Explanation: Array indexing starts from 0.

6. What is the output of the following piece of code?

public class array


{
public static void main(String args[])
{
int []arr = {1,2,3,4,5};
System.out.println(arr[5]);
}
}
a) 4
b) 5
c) ArrayIndexOutOfBoundsException
d) InavlidInputException

Answer: c
Explanation: Trying to access an element beyond the limits of an array gives
ArrayIndexOutOfBoundsException.

7. When does the ArrayIndexOutOfBoundsException occur?

a) Compile-time
b) Run-time
c) Not an error
d) Not an exception at all

Answer: b
Explanation: ArrayIndexOutOfBoundsException is a run-time exception and
the compilation is error-free.

8. Which of the following concepts make extensive use of arrays?

a) Binary trees
b) Scheduling of processes
c) Caching
d) Spatial locality

Answer: d

Explanation: Whenever a particular memory location is referred, it is likely


that the locations nearby are also referred, arrays are stored as contigous
blocks in memory, so if you want to access array elements, spatial locality
makes it to access quickly.

9. What are the advantages of arrays?


a) Objects of mixed data types can be stored
b) Elements in an array cannot be sorted
c) Index of first element of an array is 1
d) Easier to store elements of same data type

Answer: d
Explanation: Arrays stores elements of same data type and present in
continuous memory locations.

10. What are the disadvantages of arrays?

a) Data structure like queue or stack cannot be implemented


b) There are chances of wastage of memory space if elements inserted in an array
are lesser than the allocated size
c) Index value of an array can be negative
d) Elements are sequentially accessed

Answer: b
Explanation: Arrays are of fixed size. If we insert elements less than the
allocated size, unoccupied positions can’t be used again. Wastage will occur in
memory.

11. Assuming int is of 4bytes, what is the size of int arr[15];?

a) 15
b) 19
c) 11
d) 60

Answer: d
Explanation: Since there are 15 int elements and each int is of 4bytes, we get
15*4 = 60 bytes.

12. In general, the index of the first element in an array is __________

a) 0
b) -1
c) 2
d) 1

Answer: a
Explanation: In general, Array Indexing starts from 0. Thus, the index of the
first element in an array is 0.

13. Elements in an array are accessed _____________

a) randomly
b) sequentially
c) exponentially
d) logarithmically

Answer: a
Explanation: Elements in an array are accessed randomly. In Linked lists,
elements are accessed sequentially.

14. Index of arrays in C programming language starts from


a) 0
b) 1
c) either 0 or 1
d) undefined

Answer: a

15. Arrays are best data structures


a) for relatively permanent collections of data
b) for the size of the structure and the data in the structure are constantly
changing
c) for both of above situation
d) for non of above situation
Answer: a

16. A …………………… does not keep track of address of every element in the list.
a) Stack
b) String
c) Linear Array
d) Queue
Answer: (c).Linear array

17. The memory address of the first element of an array is called


a) floor address
b) foundation address
c) first address
d) base address

Answer: (d). Base Address

18.The memory address of fifth element of an array can be calculated by the


formula
a) LOC(Array[5]=Base(Array)+w(5-lower bound), where w is the number
of words per memory cell for the array
b) LOC(Array[5])=Base(Array[5])+(5-lower bound), where w is the number
of words per memory cell for the array
c) LOC(Array[5])=Base(Array[4])+(5-Upper bound), where w is the number
of words per memory cell for the array
d) None of above

Answer: (a).
LOC(Array[5]=Base(Array)+w(5-lower bound), where w is the number of words
per memory cell for the array

19. Which of these best describes an array?

A. A data structure that shows a hierarchical behavior


B. Container of objects of similar types
C. Container of objects of mixed types
D. All of the mentioned

Ans : B

Explanation: Array contains elements only of the same type.

20. Consider an array A[20, 10], assume 4 words per memory cell and the
base address of array A is 100. What is the address of A[11, 5] ? Assume row
major storage.
A. 560
B. 565
C. 570
D. 575

Ans : A

Explanation: Array contains elements only of the same type.

21. The smallest element of an array's index is called its

A. lower bound.
B. upper bound.
C. range.
D. extraction.

Ans : A

22. Each array declaration need not give, implicitly or explicitly, the
information about

A. the name of array


B. the data type of array
C. the first data from the set to be stored
D. the index set of the array

Ans : C

23. The elements of an array are stored successively in memory cells


because

A. by this way computer can keep track only the address of the first element
and the addresses of other elements can be calculated
B. the architecture of computer memory does not allow arrays to store other
than serially
C. both of above
D. none of above

Ans : A
24. Two dimensional arrays are also called

A. tables arrays
B. matrix arrays
C. both of above
D. none of above

Ans : C

25. An array elements are always stored in ________ memory locations.

A. Sequential
B. Random
C. Sequential and Random
D. None of the above

Ans : A

26. If more than one subscript is used, an array is known as a__________.

A. One- dimensional array


B. Single dimensional array
C. Multi- dimensional array
D. None of the above

Ans : C

27. Once an array is declared and initialized, various operations, such as,_can
be performed on the array.

A. Traversing and searching


B. Insertion and deletion
C. Sorting and merging
D. All of the above

Ans : d
28. To perform an operation on an array, the elements of the array need to be
accessed. The process of accessing each element of an array is known
as__________.

A. Insertion
B. Traversal
C. Both (a) and (b)
D. None of the above

Ans : B

29. The process of finding the occurrence of a particular element in an array


is known as_______

A. Linear search
B. Binary search
C. Searching
D. None of the above

Ans : C

30. A search is said to be successful or unsuccessful depending on whether the


data item is_________.

A. Found or not
B. Not Found
C. It is irrelevant
D. None of the above

Ans : A

You might also like