0% found this document useful (0 votes)
6 views5 pages

Singly Link List

This document contains a series of multiple choice questions and answers focused on arrays and their operations in programming, particularly in C and Java. Key topics include array initialization, multidimensional arrays, and exceptions related to array access. The document also discusses the advantages and disadvantages of using arrays, as well as memory considerations.

Uploaded by

sikanoah844
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views5 pages

Singly Link List

This document contains a series of multiple choice questions and answers focused on arrays and their operations in programming, particularly in C and Java. Key topics include array initialization, multidimensional arrays, and exceptions related to array access. The document also discusses the advantages and disadvantages of using arrays, as well as memory considerations.

Uploaded by

sikanoah844
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Data Structure Questions and Answers – Array and Array

Operations

This set of Data Structure Multiple Choice Questions & Answers (MCQs) focuses on
“Array and Array Operations”.

1. Which of these best describes an array?


a) A data structure that shows a hierarchical behavior
b) Container of objects of similar types
c) Arrays are immutable once initialised
d) Array is not a data structure
View Answer

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);
View Answer

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);
View Answer

Answer: c
Explanation: Note that int arr[]; is declaration whereas int arr[] = new int[3]; is to
instantiate an array.

advertisement
advertisement

4. Which of the following is the correct way to declare a multidimensional array in Java?
a) int[] arr;
b) int arr[[]];
c) int[][]arr;
d) int[[]] arr;
View Answer

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 Java code?

Subscribe Now: Data Structure Newsletter | Important Subjects Newsletters

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
View Answer

Answer: a
Explanation: Array indexing starts from 0.

advertisement

6. What is the output of the following Java 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
View Answer

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

advertisement

7. When does the ArrayIndexOutOfBoundsException occur?


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

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
View Answer

Answer: d
Explanation: Whenever a particular memory location is referred to, it is likely that the
locations nearby are also referred, arrays are stored as contiguous 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
View Answer

Answer: d
Explanation: Arrays store elements of the 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
View Answer

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
View Answer

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

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


a) 0
b) -1
c) 2
d) 1
View Answer
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
View Answer

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

You might also like