MCQ IN COMPUTER SCIENCE & ENGINEERING

COMPUTER SCIENCE AND ENGINEERING

DATA STRUCTURES

Question [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
What is the difference between an array and a list?
A
An array holds numbers, whereas a list holds strings
B
An array can only hold data of the same data type, whereas lists can hold values of different data types
C
An array holds both numbers and strings, whereas a list only holds numbers
D
None of the above
Explanation: 

Detailed explanation-1: -The kinds of values that you can store in a list type are determined by the element format, whereas for an array the elements are always values of a specific type.

Detailed explanation-2: -List is used to collect items that usually consist of elements of multiple data types. An array is also a vital component that collects several items of the same data type. List cannot manage arithmetic operations. Array can manage arithmetic operations.

Detailed explanation-3: -An array is a fixed-length data structure. ArrayList is a variable-length data structure. It can be resized itself when needed.

Detailed explanation-4: -An array can be of any data type, but can only hold a single data type. Specifically, you can declare an array that holds strings and an array that holds integers, but you cannot declare a single array that holds both strings AND integers.

Detailed explanation-5: -In an array, data is stored in a contiguous memory location, and the size of an array cannot be altered at run time due to the risk of overwriting. While in a linked list, each data node points to the next node where data is stored in non-contiguous locations, thus allowing dynamic size allocation at run time.

There is 1 question to complete.