Unit 4 - Practice Quiz

CSE101

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

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

2 If an array is declared as int arr[5] = {1, 2, 3};, what are the values of arr[3] and arr[4]?

A. Garbage values
B. 0 and 0
C. 3 and 0
D. Undefined

3 What is the index range for an array declared as int arr[N];?

A. 1 to
B. 0 to
C. 0 to
D. 1 to

4 How is the memory allocated for elements of an array in C?

A. In contiguous memory locations
B. In random memory locations
C. In a linked list structure
D. In a stack structure

5 Which operator is used to determine the total size in bytes occupied by an array named arr?

A. size(arr)
B. length(arr)
C. sizeof(arr)
D. count(arr)

6 Given int arr[] = {10, 20, 30, 40, 50};, what does the expression *(arr + 2) evaluate to?

A. 20
B. 30
C. The address of 30
D. 40

7 Which of the following statements about array initialization is FALSE?

A. int a[5] = {0}; sets all elements to 0.
B. int a[] = {1, 2}; sets size automatically to 2.
C. int a[2] = {1, 2, 3}; is a valid statement.
D. int a[5]; (local) contains garbage values.

8 In the expression arr[i], arr is equivalent to:

A. The value of the first element
B. The address of the first element
C. The total size of the array
D. The address of the last element

9 Is the expression 3[arr] valid in C, assuming arr is an integer array?

A. No, it is a syntax error.
B. Yes, it is equivalent to arr[3].
C. Yes, but it accesses arr[0].
D. No, it causes a runtime error.

10 What happens if you access arr[10] in an array declared as int arr[10];?

A. Compiler Error
B. Returns 0
C. Undefined Behavior
D. Resizes the array

11 Which is the correct syntax to declare a 2D array with 3 rows and 4 columns?

A. int arr[3,4];
B. int arr[3][4];
C. int arr[4][3];
D. int arr{3}{4};

12 In a 2D array int A[R][C], how is the address of element A[i][j] calculated in row-major order (assuming base address and element size )?

A.
B.
C.
D.

13 Which declaration allows omitting the first dimension size during initialization?

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

14 What is the maximum number of elements in int data[5][4];?

A. 9
B. 20
C. 54
D. 1

15 When passing a 1D array to a function void func(int a[]), what is actually passed?

A. The entire array by value (copy)
B. The base address of the array
C. The size of the array
D. The first element's value

16 Consider the function prototype void fun(int arr[10]);. Inside the function, what does sizeof(arr) return on a 32-bit system?

A. 40
B. 10
C. 4
D. Compilation Error

17 To pass a 2D array int grid[3][3] to a function, which prototype is valid?

A. void f(int grid[][]);
B. void f(int **grid);
C. void f(int grid[][3]);
D. void f(int grid[3][]);

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

A.
B.
C.
D.

19 When deleting an element from index in an array of size , what is the standard procedure?

A. Set the element to 0.
B. Shift elements from index to one position left.
C. Shift elements from index $0$ to one position right.
D. Decrease the array size variable only.

20 Which search algorithm requires the array to be sorted beforehand?

A. Linear Search
B. Binary Search
C. Both
D. Neither

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

A.
B.
C.
D.

22 In Binary Search, if the target is greater than the middle element, which part of the array is processed next?

A. The left half
B. The right half
C. Both halves
D. The search ends

23 What is the formula to calculate the middle index mid in Binary Search given low and high?

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

24 What is the maximum number of comparisons required for a Binary Search on an array of 32 elements?

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

25 How does Bubble Sort sort an array?

A. By splitting the array into halves.
B. By repeatedly swapping adjacent elements if they are in the wrong order.
C. By finding the minimum element and placing it at the beginning.
D. By inserting elements into a sorted sub-array.

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

A.
B.
C.
D.

27 How many passes are required to sort an array of size using Bubble Sort (worst case)?

A.
B.
C.
D.

28 Which optimization can be applied to Bubble Sort?

A. Use binary search for swapping.
B. Use a flag to check if any swap occurred in a pass; if not, terminate.
C. Only sort half the array.
D. Use recursion.

29 Consider int a[3][3] = {{1}, {2}, {3}};. What is the value of a[1][1]?

A. 1
B. 2
C. 3
D.

30 In C, strings are essentially:

A. A primitive data type.
B. Arrays of characters terminated by a null character.
C. Pointers to integers.
D. Objects of the String class.

31 Which library function is used to copy one string array to another?

A. strcopy()
B. strcpy()
C. copystring()
D. memcpy()

32 To transpose a square matrix of size , which operation is performed?

A. Swap row with row .
B. Swap A[i][j] with A[j][i].
C. Set A[i][j] = 0.
D. Shift all elements right.

33 Which of the following is a valid application of a 2D array?

A. Storing a list of names.
B. Representing a Matrix or Grid.
C. Implementing a Stack.
D. Calculating factorial.

34 If int a[] = {1, 2, 3};, what is the result of printf("%d", a[a[1]]);?

A. 1
B. 2
C. 3
D. Garbage

35 Why is it inefficient to use an array for a dataset where frequent insertions and deletions occur in the middle?

A. Arrays cannot be resized.
B. Shifting elements takes time.
C. Arrays consume too much memory.
D. It causes memory leaks.

36 What is the output of int a[5]; printf("%d", a);?

A. The value of the first element.
B. The memory address of the first element.
C. 5
D.

37 Can array size be a variable in Standard C89 (e.g., int n=5; int a[n];)?

A. Yes, always.
B. No, size must be a constant expression.
C. Yes, if initialized.
D. Yes, if global.

38 In the context of Binary Search, what does 'Linear' vs 'Logarithmic' time complexity imply?

A. Linear is faster.
B. Logarithmic is significantly faster for large inputs.
C. They are roughly the same.
D. Linear uses less memory.

39 What happens if you try to assign one array to another directly: int a[5], b[5]; a = b;?

A. Copies elements of b to a.
B. Copies address of b to a.
C. Compilation Error.
D. Runtime Error.

40 What is a 'Sparse Matrix'?

A. A matrix with random values.
B. A matrix with mostly zero elements.
C. A matrix with mostly negative numbers.
D. A matrix that is not square.

41 Given int arr[5] = {10, 20, 30, 40, 50};, what is the result of arr[1] + 2?

A. 40
B. 22
C. 12
D. 30

42 If you pass an array to a function and modify its elements inside the function, do the changes persist in the calling function?

A. No, arrays are passed by value.
B. Yes, arrays are passed by reference (pointer).
C. Only if the array is global.
D. Only if declared static.

43 Which of the following sorting algorithms is 'Stable' (maintains relative order of equal elements)?

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

44 In a 2D array, what does arr (the name) represent conceptually?

A. A pointer to an integer.
B. A pointer to a pointer to an integer.
C. A pointer to an array of integers (pointer to a row).
D. A null pointer.

45 Which header file is usually required for standard input/output operations on arrays (like printf)?

A. <stdlib.h>
B. <conio.h>
C. <stdio.h>
D. <math.h>

46 What logic allows Linear Search to work on unsorted arrays?

A. Divide and conquer.
B. Sequential checking of every element.
C. Hashing.
D. Swapping elements.

47 If we want to sort an array in Descending order using Bubble Sort, the condition for swapping a[j] and a[j+1] should be:

A. if (a[j] > a[j+1])
B. if (a[j] < a[j+1])
C. if (a[j] == a[j+1])
D. if (a[j] != a[j+1])

48 What is the space complexity of the Bubble Sort algorithm?

A.
B.
C.
D.

49 Accessing an array using a negative index (e.g., arr[-1]) inside a function where arr is a pointer pointing to the middle of an allocated block:

A. Is always a syntax error.
B. Is valid C and accesses memory before the pointer.
C. Always returns 0.
D. Is impossible.

50 Which initialization is valid for a string (char array)?

A. char s[] = 'Hello';
B. char s[] = "Hello";
C. char s[5] = "Hello";
D. char s = "Hello";