Unit 4 - Practice Quiz

CSE101 50 Questions
0 Correct 0 Wrong 50 Left
0/50

1 Which of the following creates an array of 10 integers in C?

A. int arr[10];
B. int arr(10);
C. int arr = {10};
D. array arr[10];

2 What is the index of the first element in a C array?

A. 1
B. 0
C. -1
D. User defined

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]?

A. 1004
B. 1008
C. 1012
D. 1016

4 What happens if you initialize an array with fewer values than its specified size? Example: int arr[5] = {1, 2};

A. Compiler error
B. Garbage values are stored in remaining positions
C. The remaining elements are initialized to 0
D. Runtime error

5 Which of the following is the correct syntax to initialize a 2D array?

A. int a[2][2] = {1, 2, 3, 4};
B. int a[2][2] = {{1, 2}, {3, 4}};
C. int a[][] = {1, 2, 3, 4};
D. Both A and B

6 In a 2D array declared as int arr[3][4];, how many total elements are there?

A. 7
B. 12
C. 16
D. Unknown

7 How are two-dimensional arrays stored in memory in C?

A. Row-major order
B. Column-major order
C. Randomly
D. Linked list format

8 Which of the following allows you to omit the size of the array during declaration?

A. int arr[];
B. int arr[] = {1, 2, 3};
C. int arr[?];
D. Never allowed

9 What is the output of the following snippet?
int a[5] = {10, 20, 30, 40, 50}; printf("%d", a[5]);

A. 50
B. 0
C. Garbage value or undefined behavior
D. Compiler Error

10 Which header file is required to use arrays in C?

A. <array.h>
B. <stdlib.h>
C. <stdio.h>
D. None

11 When passing an array to a function, what is actually passed?

A. The value of the first element
B. The value of all elements
C. The address of the first element
D. The size of the array

12 Which function prototype is valid for passing a 1D array?

A. void func(int arr);
B. void func(int arr[]);
C. void func(int *arr);
D. Both B and C

13 To pass a 2D array int arr[3][4] to a function, which dimension must be specified in the parameter list?

A. The first dimension (rows)
B. The second dimension (columns)
C. Both dimensions
D. Neither

14 What is the time complexity to insert an element at the beginning of an array of size ?

A.
B.
C.
D.

15 What is the precondition for performing a Binary Search?

A. Array must be of integer type
B. Array must be sorted
C. Array must contain unique elements
D. Array size must be a power of 2

16 What is the worst-case time complexity of Linear Search?

A.
B.
C.
D.

17 In Binary Search, if the middle element is less than the target value, where do we search next?

A. The left half
B. The right half
C. The whole array again
D. Stop searching

18 What is the maximum number of comparisons required for a binary search in an array of size 32?

A. 32
B. 16
C. 6
D. 5

19 Which sorting algorithm compares adjacent elements and swaps them if they are in the wrong order?

A. Selection Sort
B. Insertion Sort
C. Bubble Sort
D. Quick Sort

20 What is the worst-case time complexity of Bubble Sort?

A.
B.
C.
D.

21 How can Bubble Sort be optimized for the best-case scenario (already sorted array)?

A. By using recursion
B. By using a flag to detect if any swap occurred in a pass
C. By sorting half the array at a time
D. It cannot be optimized

22 In Bubble Sort, after the first pass through an array of elements, which element is guaranteed to be in its correct position?

A. The smallest element
B. The largest element
C. The median element
D. None

23 What is the logic to delete an element at index pos in an array of size n?

A. Set arr[pos] = 0
B. Shift elements from pos+1 to n-1 one step left
C. Shift elements from 0 to pos-1 one step right
D. Swap arr[pos] with arr[n-1]

24 Consider int arr[5] = {1, 2, 3, 4, 5};. What is the value of *(arr + 2)?

A. 1
B. 2
C. 3
D. Address of 3

25 Which formula correctly calculates the address of A[i][j] in a 2D array with columns stored in row-major order?

A.
B.
C.
D.

26 What is the result of sizeof(arr) / sizeof(arr[0])?

A. The size of the array in bytes
B. The number of elements in the array
C. The size of the first element
D. Compiler error

27 Which of the following is a valid application of arrays?

A. Implementing Matrices
B. Implementing Stacks and Queues
C. String handling
D. All of the above

28 In the declaration int (*p)[10];, what is p?

A. An array of 10 integer pointers
B. A pointer to an array of 10 integers
C. A pointer to a function returning an integer
D. An integer pointer

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])?

A. Change > to <
B. Change > to >=
C. Change j+1 to j-1
D. Change the outer loop

30 What is the formula for the middle index in Binary Search to prevent integer overflow?

A. mid = (low + high) / 2
B. mid = low + (high - low) / 2
C. mid = low + high
D. mid = (low - high) / 2

31 Which loop structure is primarily used to traverse a 2D array?

A. Single for loop
B. Nested for loops
C. do-while loop
D. switch statement

32 Can the size of an array be changed at runtime in standard C89?

A. Yes, using realloc
B. Yes, by assigning a new size
C. No, arrays are fixed-size
D. Yes, if declared as static

33 What is the output of int a[]={1,2,3}; printf("%d", 2[a]);?

A. Compiler Error
B. 1
C. 2
D. 3

34 In a Bubble Sort of an array of size , how many passes are required in the worst case?

A.
B.
C.
D.

35 When inserting an element into an array at a specific index, what should be checked first?

A. If the element is positive
B. If the array has reached its capacity
C. If the array is sorted
D. If the index is prime

36 What is the best case time complexity for Linear Search?

A.
B.
C.
D.

37 How do you calculate the number of columns in a 2D array matrix with R rows and C columns using sizeof?

A. sizeof(matrix) / sizeof(int)
B. sizeof(matrix[0]) / sizeof(int)
C. sizeof(matrix) / sizeof(matrix[0])
D. sizeof(matrix[0][0])

38 Which of the following string declarations is valid?

A. char str[5] = "Hello";
B. char str[] = "Hello";
C. char str[5] = {'H','e','l','l','o'};
D. B and C

39 What value indicates failure in a standard search function (Linear/Binary)?

A. 0
B. 1
C. -1
D. NULL

40 Which sorting algorithm is known to be 'stable'?

A. Selection Sort
B. Quick Sort
C. Bubble Sort
D. Heap Sort

41 What is a 'Sparse Matrix'?

A. A matrix with all zeros
B. A matrix with mostly zero elements
C. A matrix with no zeros
D. A matrix with random numbers

42 In the inner loop of Bubble Sort for(j = 0; j < n - 1 - i; j++), why do we subtract i?

A. To prevent index out of bounds
B. Because the last i elements are already sorted
C. To increase speed arbitrarily
D. It is a syntax requirement

43 What does the following declaration mean? int table[2][3] = { {1}, {2, 3} };

A. table[0][0]=1, rest of row 0 is 0; table[1][0]=2, table[1][1]=3, table[1][2]=0
B. Compiler Error
C. All values are random
D. table[0][0]=1, table[0][1]=2, table[0][2]=3

44 If arr is an array of int, what type is &arr?

A. int *
B. int **
C. int (*)[N] where N is size
D. int

45 Which of the following is NOT a valid way to access element 5 in int x[10]?

A. x[5]
B. *(x + 5)
C. 5[x]
D. &x + 5

46 What is the primary disadvantage of using a standard array compared to a linked list?

A. Slow access time
B. Fixed size
C. Cannot store integers
D. Complex syntax

47 If you are implementing a matrix multiplication of and , what is the condition for validity?

A.
B.
C.
D.

48 Given int arr[] = {10, 20, 30, 40, 50}; and int *p = arr;, what is the value of *++p?

A. 10
B. 20
C. 30
D. 11

49 Which searching algorithm requires space complexity (ignoring the array storage itself)?

A. Linear Search
B. Binary Search (Iterative)
C. Both A and B
D. None

50 In C, uninitialized static arrays are automatically initialized to:

A. Garbage values
B. Zeros
C. Null pointers
D. Compiler Error