Unit 4 - Practice Quiz

CSE109 50 Questions
0 Correct 0 Wrong 50 Left
0/50

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

A. int array(10);
B. array int[10];
C. int array{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 NULL.
B. It returns the last element.
C. It returns 0.
D. It results in undefined behavior (Garbage value or crash).

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

A. Column-major order
B. Row-major order
C. Diagonal order
D. Random 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 size must be a power of 2.
B. The array must not contain duplicates.
C. The array must be of integer type.
D. The array must be sorted.

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 middle element.
B. The smallest 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. The size of the array.
B. A copy of the entire array.
C. The value of the first element.
D. The address of the first element.

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) / 2;
C. mid = low + (high - low) / 2;
D. mid = high - low / 2;

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

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

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

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

13 What does the & operator yield in pointer expressions?

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

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

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

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

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

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 that has not been initialized.
B. A pointer assigned to NULL.
C. A pointer to a void type.
D. A pointer pointing to a memory location that has been deleted or freed.

18 What is a 'Wild Pointer'?

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

19 What is a 'void pointer'?

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

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. 30
C. Garbage value
D. 20

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 integer.
B. A function returning a pointer.
C. A pointer to an array of 10 integers.
D. An array of 10 pointers to integers.

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

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

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

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

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

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

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. EMPTY
B. NULL
C. VOID
D. ZERO

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

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

30 Which statement correctly frees memory pointed to by ptr?

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

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

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

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

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

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. p is an int, q is a pointer to int.
B. Both are integers.
C. p is a pointer to int, q is an int.
D. Both are pointers to int.

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

A. It is harder to implement.
B. It requires sorted data.
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. %p
B. %x
C. %u
D. %d

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 last element becomes NULL.
C. The array variable is re-declared.
D. We logically track the number of valid elements, though physical memory remains allocated.

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

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

39 What is the purpose of the indirection operator?

A. To multiply two variables.
B. To access the value at a memory address.
C. To get the address of a variable.
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[0]
B. s
C. &s
D. *s

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

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

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

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

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 that cannot be accessed via pointers.
D. A matrix where the majority of elements are zero.

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

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

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

A. No, it causes a compile error.
B. Yes, it compares the values inside the arrays.
C. Yes, it compares memory addresses, but behavior is undefined if not in the same aggregate object.
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 perform mathematical matrix multiplication.
C. To store a list of strings of varying lengths.
D. To avoid using pointers.

48 Which header file is generally needed to use NULL?

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

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

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

50 What is the result of *&var?

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