Unit 4 - Practice Quiz
1 Which of the following creates an array of 10 integers in C?
int arr[10];
int arr(10);
int arr = {10};
array arr[10];
2 What is the index of the first element in a C array?
3
If an integer array arr starts at memory address 1000 and the size of an integer is 4 bytes, what is the address of arr[3]?
4
What happens if you initialize an array with fewer values than its specified size? Example: int arr[5] = {1, 2};
5 Which of the following is the correct syntax to initialize a 2D array?
int a[2][2] = {1, 2, 3, 4};
int a[2][2] = {{1, 2}, {3, 4}};
int a[][] = {1, 2, 3, 4};
6
In a 2D array declared as int arr[3][4];, how many total elements are there?
7 How are two-dimensional arrays stored in memory in C?
8 Which of the following allows you to omit the size of the array during declaration?
int arr[];
int arr[] = {1, 2, 3};
int arr[?];
9
What is the output of the following snippet?
int a[5] = {10, 20, 30, 40, 50}; printf("%d", a[5]);
10 Which header file is required to use arrays in C?
<array.h>
<stdlib.h>
<stdio.h>
11 When passing an array to a function, what is actually passed?
12 Which function prototype is valid for passing a 1D array?
void func(int arr);
void func(int arr[]);
void func(int *arr);
13
To pass a 2D array int arr[3][4] to a function, which dimension must be specified in the parameter list?
14 What is the time complexity to insert an element at the beginning of an array of size ?
15 What is the precondition for performing a Binary Search?
16 What is the worst-case time complexity of Linear Search?
17 In Binary Search, if the middle element is less than the target value, where do we search next?
18 What is the maximum number of comparisons required for a binary search in an array of size 32?
19 Which sorting algorithm compares adjacent elements and swaps them if they are in the wrong order?
20 What is the worst-case time complexity of Bubble Sort?
21 How can Bubble Sort be optimized for the best-case scenario (already sorted array)?
22 In Bubble Sort, after the first pass through an array of elements, which element is guaranteed to be in its correct position?
23
What is the logic to delete an element at index pos in an array of size n?
arr[pos] = 0
pos+1 to n-1 one step left
0 to pos-1 one step right
arr[pos] with arr[n-1]
24
Consider int arr[5] = {1, 2, 3, 4, 5};. What is the value of *(arr + 2)?
25
Which formula correctly calculates the address of A[i][j] in a 2D array with columns stored in row-major order?
26
What is the result of sizeof(arr) / sizeof(arr[0])?
27 Which of the following is a valid application of arrays?
28
In the declaration int (*p)[10];, what is p?
29
If you want to sort an array in descending order using Bubble Sort, what change is needed in the condition if (arr[j] > arr[j+1])?
> to <
> to >=
j+1 to j-1
30 What is the formula for the middle index in Binary Search to prevent integer overflow?
mid = (low + high) / 2
mid = low + (high - low) / 2
mid = low + high
mid = (low - high) / 2
31 Which loop structure is primarily used to traverse a 2D array?
for loop
for loops
do-while loop
switch statement
32 Can the size of an array be changed at runtime in standard C89?
realloc
static
33
What is the output of int a[]={1,2,3}; printf("%d", 2[a]);?
34 In a Bubble Sort of an array of size , how many passes are required in the worst case?
35 When inserting an element into an array at a specific index, what should be checked first?
36 What is the best case time complexity for Linear Search?
37
How do you calculate the number of columns in a 2D array matrix with R rows and C columns using sizeof?
sizeof(matrix) / sizeof(int)
sizeof(matrix[0]) / sizeof(int)
sizeof(matrix) / sizeof(matrix[0])
sizeof(matrix[0][0])
38 Which of the following string declarations is valid?
char str[5] = "Hello";
char str[] = "Hello";
char str[5] = {'H','e','l','l','o'};
39 What value indicates failure in a standard search function (Linear/Binary)?
40 Which sorting algorithm is known to be 'stable'?
41 What is a 'Sparse Matrix'?
42
In the inner loop of Bubble Sort for(j = 0; j < n - 1 - i; j++), why do we subtract i?
i elements are already sorted
43
What does the following declaration mean? int table[2][3] = { {1}, {2, 3} };
table[0][0]=1, rest of row 0 is 0; table[1][0]=2, table[1][1]=3, table[1][2]=0
table[0][0]=1, table[0][1]=2, table[0][2]=3
44
If arr is an array of int, what type is &arr?
int *
int **
int (*)[N] where N is size
int
45
Which of the following is NOT a valid way to access element 5 in int x[10]?
x[5]
*(x + 5)
5[x]
&x + 5
46 What is the primary disadvantage of using a standard array compared to a linked list?
47 If you are implementing a matrix multiplication of and , what is the condition for validity?
48
Given int arr[] = {10, 20, 30, 40, 50}; and int *p = arr;, what is the value of *++p?
49 Which searching algorithm requires space complexity (ignoring the array storage itself)?
50
In C, uninitialized static arrays are automatically initialized to: