WorksheetsQuiz on Arrays
Total questions: 100
Worksheet time: 50mins
What is an array?
A group of data elements of the same data type stored continuously in memory and sharing a single name.
A single data element stored in memory.
A group of unrelated data elements stored randomly in memory.
A collection of data elements with different data types.
Which of the following is NOT a type of array mentioned in the material?
Circular Array
One Dimensional Array
Two Dimensional Array
Multi Dimensional Array
How is a one dimensional array accessed?
Using a single index
Using two indices
Using three indices
Using a pointer
What is the correct syntax to declare an array in C?
DataType ArrayName[ Size ];
ArrayName DataType( Size );
Size[ ArrayName ] DataType;
DataType[ ArrayName ] Size;
What does the number inside the square brackets in an array declaration represent?
The size of the array
The data type of the array
The name of the array
The value of the first element
What does the diagram represent in the context of arrays?
A one dimensional array with five elements
A two dimensional array with five rows
A multi dimensional array with five columns
A pointer to five variables
What is an array index also called?
Subscript
Pointer
Variable
Function
Why must the size of an array be specified at the time of declaration?
Because the compiler needs to allocate a continuous block of memory for the declared number of elements.
Because the array can change size later.
Because the data type depends on the size.
Because the array name depends on the size.
What is the starting value of an array index?
0
1
-1
Any value
Once an array is declared, can its size be changed?
No, the size cannot be changed.
Yes, the size can be changed.
Only if the array is empty.
Only if the array is full.
Which of the following is called the upper boundary in an array index?
The first index value
The last index value (size-1)
The middle index value
The index value 0
What is the correct syntax to access an element of an array in C?
Array_name(index)
Array_name.index
Array_name[index]
Array_name:index
If int a[5] = {10, 34, 56, 78, 90}; what value does a[2] refer to?
10
34
56
78
Which statement is true about array declaration and definition in C?
Declaration and definition store values in the array
Declaration and definition only reserve space for the elements
Declaration and definition initialize all elements to zero
Declaration and definition read values from the keyboard
How many ways can elements be initialized in an array according to the material?
1
2
3
4
Which of the following code snippets correctly prints all elements of the array int a[5] = {10, 34, 56, 78, 90} using a loop?
for(int i=0; i<5; i++) { printf("%d", a[i]); }
for(int i=1; i<=5; i++) { printf("%d", a[i]); }
printf("%d", a[5]);
printf("%d", a[0,1,2,3,4]);
What is the correct syntax for compile time initialization of an array in C?
Data_Type Array_Name[ no-of-elements]={list of elements};
Data_Type Array_Name(list of elements);
Array_Name Data_Type[ no-of-elements]={list of elements};
Data_Type Array_Name={list of elements};
If you declare int b[5]={10,34,56}; in C, what will be the values of b[3] and b[4]?
0 and 0
10 and 34
56 and 10
34 and 56
What happens if you do not provide any elements during array initialization, for example int x[4]={};?
All elements are initialized to 0
All elements are initialized to 1
All elements are initialized to -1
All elements are left uninitialized
Given the array declaration float x[]={3.2, 60.3, 4.5, 1.2};, what is the value at index 1?
60.3
3.2
4.5
1.2
Why is compile time initialization of arrays also called static initialization?
Because values are assigned at the time of declaration
Because values are assigned during program execution
Because values are assigned by the user input
Because values are assigned randomly
If you declare int x[4]={0};, what will be the values of all elements in the array?
0, 0, 0, 0
1, 1, 1, 1
0, 1, 2, 3
4, 4, 4, 4
Which of the following is the correct syntax for initializing an array element in C?
Array-name[index]=element;
Array-name=element[index];
element[index]=Array-name;
index=Array-name[element];
What is the value stored in A[3] after the following initialization? A[0]=10; A[1]=20; A[2]=30; A[3]=40; A[4]=50;
10
20
30
40
What do the numbers below the array elements represent?
The values of the elements
The indices of the array
The size of the array
The memory addresses
Which statement is used to read elements into an array during runtime initialization in C?
printf
scanf
cin
gets
What is the purpose of using a "for" loop with "printf" when working with arrays in C?
To initialize array elements
To print array elements
To delete array elements
To sort array elements
How does an array differ from an ordinary variable according to the provided material?
An array stores only one value, while a variable stores multiple values.
An array is a group of elements, while a variable is a container which can store a single value.
An array is used for mathematical operations, while a variable is used for logical operations.
An array is always static, while a variable is always dynamic.
If you want to print all elements of an array named 'a' of size 5, which of the following code snippets is correct?
for(i=0;i<5;i++) printf("%d\n",a[i]);
for(i=0;i<5;i++) printf("%c\n",a[i]);
for(i=0;i<4;i++) printf("%d\n",a[i]);
for(i=1;i<=5;i++) printf("%d\n",a[i]);
Which of the following best describes the capacity of an array in programming?
It can store multiple values.
It can store only one value.
It cannot store any values.
It can store values randomly.
What is the correct syntax to declare a one-dimensional array in C/C++?
Data_type Array_name[size]
Data_type Variable_Name
Array_name Data_type[size]
size[Array_name] Data_type
How is memory allocated for an array compared to a normal variable?
Memory allocation will be done continuously in memory for arrays.
Memory allocation will be done randomly in memory for arrays.
Memory allocation is not required for arrays.
Memory allocation is done only for normal variables.
Which of the following is a valid example of declaring a two-dimensional array that can store 6 elements?
int a[2][3];
int b[2][2];
int c[3][3];
int d[1][6];
What does the row_size and col_size represent in the declaration of a 2-D array?
Number of rows and columns in the array.
Type of data elements.
Name of the array.
Index values of the array.
What is the size of the matrix shown in the diagram?
3x3
2x3
3x2
1x9
Why must row_size and col_size be integer constants in a 2-D array declaration?
To ensure the array size is fixed at compile time.
To allow dynamic memory allocation.
To enable random access of elements.
To store only character data.
Which statement about initialization of arrays is correct?
Initialization assigns values to an array at the place of declaration itself.
Initialization is not required for arrays.
Initialization can only be done after declaration.
Initialization is only for variables, not arrays.
Which of the following is the correct syntax to access an element in a 2-D array?
ArrayName[Row Index][Column Index]
ArrayName(Column Index, Row Index)
ArrayName{Row Index, Column Index}
ArrayName[Column Index][Row Index]
If an array is declared as int a[2][3], how many elements does it contain?
2
3
5
6
What is the term for the representation where elements of the first row are stored in continuous memory locations followed by the second row and so on?
Column Major Representation
Row Major Representation
Matrix Representation
Array Representation
Given the array int b[2][2] = { {1,2}, {3,4} }, what value is stored at b[1][0]?
1
2
3
4
Why is the actual storage in memory of a 2-D array different from its matrix representation?
Because memory is always stored in columns
Because matrix representation is only for display
Because memory is linear and matrix is two-dimensional
Because arrays cannot be stored in memory
Which of the following best describes the process of referencing an element in a 2-D array?
Using only one index
Using two indexes or subscripts
Using the array name only
Using a pointer
What is the base address of the array shown in the diagram?
500
502
504
506
How many bytes apart are consecutive elements stored in the array?
1 byte
2 bytes
4 bytes
8 bytes
In column major representation, how are the elements of a 2D array stored in memory?
Elements of each row are stored in continuous memory locations
Elements of each column are stored in continuous memory locations
Elements are stored randomly in memory
Only the first row is stored in continuous memory locations
Given the array int a[3][4] with base address 500 and each element stored at a distance of 2 bytes, what would be the memory address of a[2][3] in row major representation?
506
514
522
520
Explain the difference between row major and column major representation of a 2D array in terms of memory storage.
Row major stores elements of each row continuously, column major stores elements of each column continuously.
Row major stores elements of each column continuously, column major stores elements of each row continuously.
Both store elements randomly.
Both store elements of the first row continuously.
What is the value stored at a[2][2] in the given 2D array?
10
11
12
9
How many elements are present in the array 'a' declared as int a[3][4]?
7
12
10
15
If the base address of the array 'a' is 500 and each integer occupies 2 bytes, what is the address of a[1][1]?
502
504
506
508
Given the memory mapping shown, which value is stored at address 510?
10
11
7
8
The memory address for a[2][1] is calculated if the base address is 500 and each integer occupies 2 bytes. Which of the following formulas is used?
By adding (row index × number of columns + column index) × size of int to the base address
By adding (column index × number of rows + row index) × size of int to the base address
By multiplying row index and column index and adding to the base address
By adding only the row index to the base address
What is the base address of the array shown in the diagram?
500
516
518
520
How many bytes apart are each element stored in the array?
2 bytes
4 bytes
8 bytes
1 byte
Which statement is used to store elements into a 2-D array during run time initialization?
scanf
printf
cin
cout
What is the correct syntax for storing elements in a 2-D array using nested loops?
for(i=0;i<rows;i++)
{
for(j=0;j<cols;j++)
{
printf(“%d “,variable[i][j]);
}
printf(“\n”);
}
for(i=0;i<rows;i++)
{
for(j=0;j<cols;j++)
{
printf(“%d “,variable[j][ji);
}
printf(“\n”);
}
for(i=0;i<rows;i++)
{
for(j=0;j<cols;j++)
{
printf(“%d “,variable[j][j]);
}
printf(“\n”);
}
for(i=0;i<rows;i++)
{
for(j=0;j<cols;j++)
{
printf(“%d “,variable[i][i]);
}
printf(“\n”);
}
Explain the difference between run time initialization and static initialization of a 2-D array.
Run time initialization uses loops and input statements, while static initialization assigns values directly in code.
Run time initialization assigns values directly in code, while static initialization uses loops and input statements.
Both methods use loops and input statements.
Both methods assign values directly in code.
What is the general format for initializing elements in a 2-D array during compile time?
Array-name[row_index][Col_index]=element;
Array-name[element][row_index][Col_index];
Array-name[Col_index][row_index]=element;
Array-name[row_index]=element[Col_index];
Which value is stored in A[1][2] according to the example provided?
60
50
40
30
What is the value at position A[0][1] in the given matrix?
20
10
30
50
Which statement correctly describes how to print all elements of a 2-D array in matrix form using C?
Use nested "for" loops and "printf" statements.
Use a single "for" loop and "scanf" statements.
Use "while" loops and "printf" statements.
Use "if" statements and "printf" statements.
In the provided example, what does the inner loop variable 'j' represent when printing a 2-D array?
Column index
Row index
Array size
Element value
(DoK Level 2) If you want to print a 2-D array with 4 rows and 5 columns, how would you modify the loop conditions in the given syntax?Consider the below program. What is the expected output?
void fun(int arr[], int start, int end) { while (start < end) { int temp = arr[start]; arr[start] = arr[end]; arr[end] = temp; start++; end--; } }
swapping the elements pairwise
sorting the elements
Reverse an array
None
(DoK Level 3) Given the array initialization: A[0][0]=10; A[0][1]=20; A[0][2]=30; A[1][0]=40; A[1][1]=50; A[1][2]=60; What is the output printed by the example code for printing the array in matrix form?
printf(“Array is \n”);
for(i=0;i<2;i++)
{
for(j=0;j<3;j++)
{
printf(“%d “,a[i][j]);
}
printf(“\n”);
}
10 40 20
10 20 30
40 50 60
30 50 60
10 20 30 60 50 40
Which of the following best describes a multi-dimensional array in C?
An array of arrays, allowing three or more dimensions
An array with only one dimension
A collection of variables of different types
A function that returns an array
What is the correct syntax to declare a three-dimensional array in C?
Datatype array_name[size1][size2][size3]
Datatype array_name(size1, size2, size3)
Datatype array_name[size1, size2, size3]
Datatype array_name{size1}{size2}{size3}
Given the initialization below, what value is stored at a[2][1][2]? Int a[3][2][3]={ { {1,2,3}, {4,5,6} }, { {11,12,13}, {14,15,16} }, { {21,22,23}, {24,25,26} } };
25
23
26
22
Based on the diagram, which group of numbers represents the 1st 2-D array in the physical representation of the 3-D array?
1, 2, 3, 4, 5, 6
11, 12, 13, 14, 15, 16
21, 22, 23, 24, 25, 26
1, 11, 21, 2, 12, 22
Why is a multi-dimensional array considered a collection of 2-D arrays in C?
Because each element is a separate variable
Because it is a collection of arrays, where each array can be a 2-D array
Because it only supports two dimensions
Because it cannot store more than one value
Which of the following statements best describes the size of an array in C?
The size of an array can be changed during program execution.
The size of an array is fixed after its declaration and cannot be modified later.
The size of an array is always determined at runtime.
The size of an array is flexible and can be increased or decreased.
What type of elements can an array in C contain?
Elements of different data types.
Only integer elements.
Elements of the same data type.
Only character elements.
In C, what is the starting index of an array?
1
-1
0
2
Which of the following is NOT a possible dimension for an array in C?
1-D array
2-D array
3-D array
4-D array
Why is accessing elements in an array fast?
Because elements are stored in random locations.
Because elements are stored at contiguous memory locations.
Because elements are stored in separate files.
Because elements are stored in a database.
Which feature of arrays allows you to access any element without touching other elements?
Sequential Access
Random Access
Linear Access
Circular Access
How does the name of an array relate to pointers in C?
The array’s name is a pointer to its last element.
The array’s name is a pointer to its first element.
The array’s name is not related to pointers.
The array’s name is a pointer to a random element.
What is bound checking in the context of arrays?
Checking if the array is sorted.
Checking if the element is present within the lower or upper boundary.
Checking if the array is empty.
Checking if the array contains duplicate elements.
What happens during array decay in C?
The array increases its dimension.
The array loses its dimension and converts into a pointer.
The array changes its data type.
The array gets deleted from memory.
Which of the following is NOT an advantage of using arrays?
Effective storage of multiple values.
Easy to access elements using index.
Modification to one element impacts all other elements.
Convenient to perform repetitive tasks using loops.
Why is it useful to implement data structures using arrays?
Arrays are always sorted.
Arrays allow random access and efficient storage.
Arrays can only store one value.
Arrays are difficult to understand.
Which statement is true about accessing elements in an array?
Accessing elements is slow because they are stored randomly.
Accessing elements is fast because they are stored continuously in memory.
Accessing elements requires searching the entire array.
Accessing elements is only possible using loops.
How does using a single name for a group of values benefit array usage?
It makes the code more complex.
It simplifies data management and access.
It restricts the number of elements.
It increases memory usage.
Which of the following is a convenient feature of arrays for performing repetitive tasks?
Using loops to access elements.
Using recursion to access elements.
Using random numbers to access elements.
Using separate variables for each element.
What is a key benefit of arrays in terms of data organization?
Arrays make data organization more difficult.
Arrays provide better data organization.
Arrays do not help in organizing data.
Arrays only work for small datasets.
Which of the following is a disadvantage of arrays?
Array size must know at compile time.
Arrays can increase or decrease in size.
Arrays can have elements of different datatypes.
Arrays do not require contiguous memory space.
What is the main difference between a single dimensional array and a multi dimensional array?
Single dimensional arrays have only one dimension, while multi dimensional arrays have multiple dimensions.
Single dimensional arrays can store different datatypes, while multi dimensional arrays cannot.
Single dimensional arrays are always larger than multi dimensional arrays.
Single dimensional arrays do not require syntax, while multi dimensional arrays do.
Which syntax correctly declares a single dimensional array in C?
Data_type Array_name[size]
DataType ArrayName[size1][size2]
int a[2][3]
int a[3][2][3]
What happens if you try to access array data out of bounds?
It leads to crashing the program or corrupting the data.
It automatically resizes the array.
It ignores the access and continues.
It converts the array into a pointer.
Which of the following statements about strings in C is correct?
A string is an array of characters which ends with a NULL character '\0'.
A string is an array of integers.
A string does not require a NULL character at the end.
A string can only contain one character.
Why does insertion or deletion of an element at the middle of an array require shifting the elements?
Because arrays store elements in contiguous memory locations.
Because arrays can increase in size automatically.
Because arrays can have different datatypes.
Because arrays do not have indexes.
Which representation is used for a multi dimensional array?
A grid with rows and columns.
A single row of numbers.
A list of characters.
A single column of numbers.
If you underestimate the array size, what is the likely consequence?
Insufficient memory for storing all elements.
Wastage of memory.
Automatic resizing of the array.
No effect on the program.
What is the datatype used to declare a string in C?
int
float
char
double
Which of the following is the correct syntax to declare a string variable in C?
string name[size];
char StringName[size];
int StringName[size];
float StringName[size];
In the declaration char sname[10];, what does the number 10 represent?
The number of strings
The maximum number of characters plus one for NULL character
The datatype of the string
The name of the string
Which operation is NOT a common operation on strings?
Reading and writing strings
Finding length of string
Multiplying two strings
Finding reverse of string
What is the purpose of the NULL character (\0) in a string?
To indicate the start of the string
To separate two strings
To mark the end of the string
To convert the string to uppercase
Which of the following is a way to declare a string without specifying its size?
char name[5] = "Hello";
char name[] = {'H', 'e', 'l', 'l', 'o', '\0'};
char name[10];
char name[5];
Refer the below diagram and identify the problem.
Normal traversal of the matrix.
Row-wise traversal of the matrix.
Column-wise traversal of the matrix.
spiral traversal of the matrix.
