Unit 4 - Practice Quiz

CSE109

1 Which of the following is the correct syntax to declare an integer array of size 10 in C?

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

2 What happens if you try to access arr[5] in an array declared as int arr[5];?

A. It returns 0.
B. It returns the last element.
C. It results in undefined behavior (Garbage value or crash).
D. It returns NULL.

3 How is a two-dimensional array initialized in memory in C?

A. Column-major order
B. Row-major order
C. Random order
D. Diagonal order

4 Which of the following correctly calculates the memory address of the element in a 1D array, given the Base Address and element size ?

A.
B.
C.
D.

5 What is the time complexity of a Linear Search in the worst case?

A.
B.
C.
D.

6 Which of the following is a strict prerequisite for performing a Binary Search?

A. The array must be sorted.
B. The array must be of integer type.
C. The array size must be a power of 2.
D. The array must not contain duplicates.

7 In Bubble Sort, after the first pass through an array of size , which element is guaranteed to be in its correct position (assuming ascending sort)?

A. The smallest element.
B. The middle element.
C. The largest element.
D. No element is guaranteed.

8 What is the maximum number of comparisons required for a Bubble Sort on an array of size ?

A.
B.
C.
D.

9 When passing an array to a function in C (e.g., void func(int arr[])), what is actually passed?

A. A copy of the entire array.
B. The value of the first element.
C. The address of the first element.
D. The size of the array.

10 What is the correct logic to calculate the middle index in Binary Search to avoid integer overflow?

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

11 Which operation is involved in inserting an element into a specific position of an array?

A. Shifting elements to the left.
B. Shifting elements to the right.
C. Swapping the first and last elements.
D. Only overwriting the element at that position.

12 Identify the correct declaration of a pointer to an integer.

A. int &ptr;
B. ptr *int;
C. int *ptr;
D. int ptr;

13 What does the & operator yield in pointer expressions?

A. The value pointed to.
B. The memory address of the operand.
C. The size of the variable.
D. The type of the variable.

14 What does the * operator do when applied to a pointer variable (e.g., *ptr)?

A. It returns the address of the pointer.
B. It returns the value stored at the address held by the pointer.
C. It declares a new pointer.
D. It casts the pointer to void.

15 If int *p points to address 1000 and the size of int is 4 bytes, what is the value of p + 1?

A. 1001
B. 1004
C. 1002
D. Unknown

16 Which of the following arithmetic operations is illegal for pointers?

A. Pointer + Integer
B. Pointer - Integer
C. Pointer - Pointer
D. Pointer + Pointer

17 What is a 'Dangling Pointer'?

A. A pointer assigned to NULL.
B. A pointer pointing to a memory location that has been deleted or freed.
C. A pointer that has not been initialized.
D. A pointer to a void type.

18 What is a 'Wild Pointer'?

A. A pointer declared but not initialized.
B. A pointer pointing to NULL.
C. A pointer to a function.
D. A pointer to an array.

19 What is a 'void pointer'?

A. A pointer that points to nothing (NULL).
B. A generic pointer that can point to any data type.
C. A pointer that cannot be reassigned.
D. A pointer with a value of 0.

20 How do you declare a 'pointer to a pointer' to an integer?

A. int *ptr;
B. int &ptr;
C. int **ptr;
D. int *&ptr;

21 Given int arr[] = {10, 20, 30}; and int *p = arr;, what is *(p + 1)?

A. 10
B. 20
C. 30
D. Garbage value

22 Which of the following expressions is equivalent to arr[i]?

A. *(arr + i)
B. &arr + i
C. *arr + i
D. arr + i

23 What does the declaration int *arr[10]; represent?

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

24 What does the declaration int (*ptr)[10]; represent?

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

25 If you subtract two pointers pointing to elements of the same array, the result is:

A. The sum of the addresses.
B. The number of bytes between them.
C. The number of elements between them.
D. Illegal operation.

26 What is the result of applying sizeof to an array passed as a parameter to a function?

A. The total size of the array in bytes.
B. The number of elements in the array.
C. The size of a pointer on the system.
D. Zero.

27 What is the best case time complexity of Bubble Sort (using a flag to detect swaps)?

A.
B.
C.
D.

28 Which constant represents a pointer that points to no valid memory address?

A. VOID
B. EMPTY
C. NULL
D. ZERO

29 For a 2D array int A[3][4], what does A represent?

A. The value of the first element A[0][0].
B. A pointer to the first row (an array of 4 ints).
C. A pointer to a pointer to an int.
D. The total size of the array.

30 Which statement correctly frees memory pointed to by ptr?

A. delete ptr;
B. dealloc(ptr);
C. free(ptr);
D. remove(ptr);

31 Can a void pointer be used for pointer arithmetic directly?

A. Yes, always.
B. No, because the size of the object it points to is unknown.
C. Yes, it assumes size of 1 byte.
D. Yes, it assumes size of int.

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

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

33 In a 2D array int M[3][3], which expression accesses the element at row i and column j using pointer arithmetic?

A. *(*(M + i) + j)
B. *((M + i) + j)
C. *(M + i + j)
D. **M + i + j

34 If you declare int *p, q;, what are the types of p and q?

A. Both are pointers to int.
B. p is a pointer to int, q is an int.
C. p is an int, q is a pointer to int.
D. Both are integers.

35 What is the primary disadvantage of Linear Search over Binary Search?

A. It requires sorted data.
B. It is harder to implement.
C. It is slower for large datasets ( vs ).
D. It uses more memory.

36 Which format specifier is typically used to print a pointer address in C?

A. %d
B. %u
C. %x
D. %p

37 When deleting an element from an array, why is the array size effectively reduced by 1?

A. Memory is physically released to OS.
B. The array variable is re-declared.
C. We logically track the number of valid elements, though physical memory remains allocated.
D. The last element becomes NULL.

38 Consider char *str = "Hello";. What happens if you try str[0] = 'h';?

A. The string becomes "hello".
B. Compiler Error.
C. Undefined behavior (often Segmentation Fault).
D. Nothing happens.

39 What is the purpose of the indirection operator?

A. To get the address of a variable.
B. To multiply two variables.
C. To access the value at a memory address.
D. To declare a new type.

40 Which of the following correctly passes a pointer ptr to a function void func(int *p)?

A. func(*ptr);
B. func(&ptr);
C. func(ptr);
D. func(ptr[]);

41 If s is a 1D array of integers, which is equivalent to &s[0]?

A. s
B. *s
C. &s
D. s[0]

42 Can you resize a static array (e.g., int a[10]) at runtime?

A. Yes, using realloc.
B. Yes, by assigning a new size.
C. No, the size is fixed at compile time.
D. Yes, if it is a global array.

43 What is the index of the last element in an array declared as double val[N]?

A. N
B. N - 1
C. N + 1
D.

44 In the context of array applications, what is a 'Sparse Matrix'?

A. A matrix with all elements as zero.
B. A matrix with elements in descending order.
C. A matrix where the majority of elements are zero.
D. A matrix that cannot be accessed via pointers.

45 What is the associativity of the pointer operator * (dereference)?

A. Left to Right
B. Right to Left
C. Random
D. No associativity

46 If int *p and int *q point to different arrays, is p < q a valid expression?

A. Yes, it compares the values inside the arrays.
B. Yes, it compares memory addresses, but behavior is undefined if not in the same aggregate object.
C. No, it causes a compile error.
D. Yes, it returns the difference in indices.

47 What is the typical use case for an 'Array of Pointers'?

A. To store a string of characters.
B. To store a list of strings of varying lengths.
C. To perform mathematical matrix multiplication.
D. To avoid using pointers.

48 Which header file is generally needed to use NULL?

A. <stdio.h> or <stddef.h>
B. <math.h>
C. <string.h> only
D. <conio.h>

49 When initializing an array int a[] = {1, 2, 3};, why can the size be omitted?

A. The size defaults to 100.
B. The compiler infers the size from the number of initializers.
C. It becomes a dynamic array.
D. It is invalid syntax.

50 What is the result of *&var?

A. The address of var.
B. The value of var.
C. Undefined.
D. The address of the pointer.