This section contains carefully selected MCQs and Previous Year Questions with explanations to help students understand concepts and prepare effectively for examinations, interviews, and competitive tests.
Q: 1Which of the following correctly initializes an array in C?
Option A
In C, an array is initialized using square brackets [] to specify its size and curly braces {} to provide initial values. The statement int LA[5] = {1,2,3,4}; correctly follows this syntax. Even though the array size is 5 and only 4 values are provided, the remaining element is automatically initialized to 0.
Q: 2To 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__________.
Option B
The process of accessing each element of an array one by one in order to perform an operation such as printing, updating, or calculating is called Array Traversal.
Q: 3What is the length of the array arr after this operation?
arr[]={1,2,3,4,5};
arr[1]=22;
arr[3]=44;
Option B
The array arr is initially defined as {1,2,3,4,5}, which contains 5 elements. The statements arr[1]=22; and arr[3]=44; only update the values at index 1 and index 3 of the existing array.
The array’s length remains unchanged by element assignments. It still contains 5 elements.
Q: 4Which of the following is best describes an array?
Option B
An array is a data structure that stores a collection of elements of the same data type (homogeneous) in contiguous memory locations.
Q: 5Which of the following correctly declares an array in C?
Option A
In C, an array is declared using the data type, array name, and size enclosed in square brackets [].
Syntax:
Data_Type Array_Name[Array_Size];
The statement int suraku[20]; follows the correct syntax for array declaration.
Q: 6The name of 1-D array itself is a __________? Choose best answer.
Option D
The name of a 1-D array in C is a constant pointer to the type of array. This means it holds the address of the first element and cannot be changed to point to another location. For example, if you have int arr[6];, then arr is a constant pointer to int, always pointing to arr[0] and cannot be reassigned.
Q: 7An __________ is a homogenous structure and starts with _________ index number.
Option C
An Array is a Homogeneous Data Structure, meaning it stores elements of the same data type. In most programming languages like C, C++, and Java, array indexing starts from 0.
Q: 8Consider the following statement:
int Data[2][4]={10,20,30,40,50,60,70,80};
Value 30 can be accessed as ___________ (assume row-major order)
Option D
In C/C++, a 2D array is stored in row-major order, which means elements are filled row by row.
Given array : int Data[2][4] = {10, 20, 30, 40, 50, 60, 70, 80};. This will be stored as:
| Row | Columns (Index) |
|---|---|
| Data[0] | 10 20 30 40 |
| Data[1] | 50 60 70 80 |
So, the indexing becomes:
Q: 9How are elements of dynamic array stored in the memory?
Option D
In a dynamic array, elements are stored next to each other (contiguous) in memory, just like a regular array (static array). The difference is that the size of a dynamic array is decided at runtime and memory is allocated dynamically in the heap section.
Q: 10What are the disadvantages of static arrays?
Option C
Static Arrays have a fixed size that must be defined at compile time. If fewer elements are stored than the allocated size, the unused locations remain empty, leading to wastage of memory space. This is the main disadvantage of static arrays.
Q: 11What is a 2D Array?
Option D
A 2D array is an array of arrays, where each element of the main array is itself another array. It is commonly used to store data in the form of rows and columns, like a table or matrix.
Q: 12The array name itself is a?
Option A
In C, the array name itself behaves like a pointer constant. This means it holds the address of the first element of the array.
Q: 13The name of 2-D array itself is a _________? Choose best answer.
Option C
In C, a two-dimensional array is essentially an array of one-dimensional arrays. Therefore, the name of a 2-D array represents the address of its first row, which itself is a 1-D array. Since the number of columns is fixed in memory layout, each row is treated as a 1-D array of fixed column size.
Q: 14Which method is used to access elements in an array?
Option B
Arrays use the random-access method to access elements. This means any element of the array can be accessed directly using its index, without accessing previous elements. Due to this direct indexing and contiguous memory allocation, accessing arr[i] takes constant time (O(1)).
Q: 15An array is finite collection of?
Option B
An array is a data structure that stores a fixed number of elements of similar types. This means every value inside an array should be either all integers, all floats, all characters, etc. This property is called homogeneous because the elements are similar in type.
Thank you so much for taking the time to read my Computer Science MCQs section carefully. Your support and interest mean a lot, and I truly appreciate you being part of this journey. Stay connected for more insights and updates! If you'd like to explore more tutorials and insights, check out my YouTube channel.
Don’t forget to subscribe and stay connected for future updates.