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.
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.