1Which 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];
Correct Answer: int array[10];
Explanation:
In C, an array is declared by specifying the data type, followed by the array name, and the size in square brackets: type name[size];.
Incorrect! Try again.
2What 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).
Correct Answer: It results in undefined behavior (Garbage value or crash).
Explanation:
Array indices in C are zero-based. For int arr[5], the valid indices are 0 to 4. Accessing index 5 is an out-of-bounds access, leading to undefined behavior.
Incorrect! Try again.
3How is a two-dimensional array initialized in memory in C?
A.Column-major order
B.Row-major order
C.Diagonal order
D.Random order
Correct Answer: Row-major order
Explanation:
C compilers store multidimensional arrays in row-major order, meaning elements of the first row are stored contiguously, followed by the second row, and so on.
Incorrect! Try again.
4Which 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.
Correct Answer:
Explanation:
Since array indexing starts at 0, the address is the Base Address plus the index multiplied by the size of each element.
Incorrect! Try again.
5What is the time complexity of a Linear Search in the worst case?
A.
B.
C.
D.
Correct Answer:
Explanation:
In the worst case (element not present or at the end), linear search must compare the target value with every element in the array of size .
Incorrect! Try again.
6Which 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.
Correct Answer: The array must be sorted.
Explanation:
Binary search logic relies on dividing the search interval in half based on whether the target is lower or higher than the middle element. This only works if the data is sorted.
Incorrect! Try again.
7In 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.
Correct Answer: The largest element.
Explanation:
Bubble sort works by repeatedly swapping adjacent elements if they are in the wrong order. In each pass, the largest remaining element 'bubbles up' to the end of the array.
Incorrect! Try again.
8What is the maximum number of comparisons required for a Bubble Sort on an array of size ?
A.
B.
C.
D.
Correct Answer:
Explanation:
In the worst case, bubble sort makes comparisons, which sums to , resulting in complexity.
Incorrect! Try again.
9When 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.
Correct Answer: The address of the first element.
Explanation:
In C, arrays decay to pointers when passed to functions. The function receives a pointer to the first element (base address), not a full copy of the array.
Incorrect! Try again.
10What 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;
Correct Answer: mid = low + (high - low) / 2;
Explanation:
low + (high - low) / 2 is mathematically equivalent to (low + high) / 2 but prevents potential overflow if low + high exceeds the maximum integer limit.
Incorrect! Try again.
11Which 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.
Correct Answer: Shifting elements to the right.
Explanation:
To insert an element at index , all elements from index to the end must be shifted one position to the right to create space.
Incorrect! Try again.
12Identify the correct declaration of a pointer to an integer.
A.int ptr;
B.int &ptr;
C.ptr *int;
D.int *ptr;
Correct Answer: int *ptr;
Explanation:
The asterisk * before the variable name indicates that the variable is a pointer. int *ptr; declares a pointer capable of holding the address of an integer.
Incorrect! Try again.
13What 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.
Correct Answer: The memory address of the operand.
Explanation:
The & operator is the 'address-of' operator. It returns the memory address of the variable it precedes.
Incorrect! Try again.
14What 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.
Correct Answer: It returns the value stored at the address held by the pointer.
Explanation:
When used in an expression (not declaration), * is the dereference operator. It accesses the value at the memory address stored in the pointer.
Incorrect! Try again.
15If 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
Correct Answer: 1004
Explanation:
Pointer arithmetic scales by the size of the data type. Adding 1 to an int* increases the address by 1 * sizeof(int). If sizeof(int) is 4, .
Incorrect! Try again.
16Which of the following arithmetic operations is illegal for pointers?
A.Pointer - Integer
B.Pointer + Integer
C.Pointer - Pointer
D.Pointer + Pointer
Correct Answer: Pointer + Pointer
Explanation:
Adding two memory addresses together has no logical meaning in C programming and is illegal. Subtracting pointers is valid (gives distance), as is adding/subtracting integers to/from pointers.
Incorrect! Try again.
17What 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.
Correct Answer: A pointer pointing to a memory location that has been deleted or freed.
Explanation:
A dangling pointer arises when an object is deleted or deallocated, without modifying the value of the pointer, so the pointer still points to the memory location of the deallocated memory.
Incorrect! Try again.
18What 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.
Correct Answer: A pointer declared but not initialized.
Explanation:
Uninitialized pointers are known as wild pointers because they point to some arbitrary memory location and may cause a program to crash or behave unexpectedly.
Incorrect! Try again.
19What 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).
Correct Answer: A generic pointer that can point to any data type.
Explanation:
A void * is a generic pointer type. It can hold the address of any type, but it cannot be dereferenced directly without casting.
Incorrect! Try again.
20How do you declare a 'pointer to a pointer' to an integer?
A.int *&ptr;
B.int *ptr;
C.int **ptr;
D.int &ptr;
Correct Answer: int **ptr;
Explanation:
A double asterisk ** is used to declare a pointer to a pointer. int **ptr is a pointer that stores the address of an int *.
Incorrect! Try again.
21Given int arr[] = {10, 20, 30}; and int *p = arr;, what is *(p + 1)?
A.10
B.30
C.Garbage value
D.20
Correct Answer: 20
Explanation:
p points to arr[0] (10). p + 1 points to arr[1]. Dereferencing it *(p + 1) yields the value 20.
Incorrect! Try again.
22Which of the following expressions is equivalent to arr[i]?
A.arr + i
B.&arr + i
C.*arr + i
D.*(arr + i)
Correct Answer: *(arr + i)
Explanation:
In C, array subscript notation arr[i] is defined in terms of pointer arithmetic as *(arr + i).
Incorrect! Try again.
23What 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.
Correct Answer: An array of 10 pointers to integers.
Explanation:
Due to operator precedence, [] binds tighter than *. Thus, it is an array of size 10, where each element is of type int * (pointer to integer).
Incorrect! Try again.
24What 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.
Correct Answer: A pointer to an array of 10 integers.
Explanation:
The parentheses (*ptr) force the * to bind to ptr first. So ptr is a pointer. It points to [10] (an array of 10 integers).
Incorrect! Try again.
25If 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.
Correct Answer: The number of elements between them.
Explanation:
Pointer subtraction returns the difference in the number of elements (indices), not bytes. The compiler handles the division by sizeof(type) automatically.
Incorrect! Try again.
26What 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.
Correct Answer: The size of a pointer on the system.
Explanation:
Because arrays decay to pointers when passed to functions, sizeof(arr) inside the function returns the size of the pointer (e.g., 4 or 8 bytes), not the full array size.
Incorrect! Try again.
27What is the best case time complexity of Bubble Sort (using a flag to detect swaps)?
A.
B.
C.
D.
Correct Answer:
Explanation:
If the array is already sorted, an optimized Bubble Sort (with a flag) makes one pass, performs zero swaps, detects the sorted state, and terminates. The complexity is .
Incorrect! Try again.
28Which constant represents a pointer that points to no valid memory address?
A.EMPTY
B.NULL
C.VOID
D.ZERO
Correct Answer: NULL
Explanation:
NULL is a macro defined in <stddef.h> (and others) representing a null pointer constant.
Incorrect! Try again.
29For 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.
Correct Answer: A pointer to the first row (an array of 4 ints).
Explanation:
The name of a 2D array decays to a pointer to its first element. Since it is an array of arrays, the first element is the first row. The type is int (*)[4].
Incorrect! Try again.
30Which statement correctly frees memory pointed to by ptr?
A.dealloc(ptr);
B.remove(ptr);
C.free(ptr);
D.delete ptr;
Correct Answer: free(ptr);
Explanation:
In C, free() is the standard library function (from stdlib.h) used to deallocate memory previously allocated by malloc, calloc, or realloc.
Incorrect! Try again.
31Can 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.
Correct Answer: No, because the size of the object it points to is unknown.
Explanation:
Standard C does not allow arithmetic on void* because void has no size. (Note: GCC extension allows it by treating it as size 1, but it is not standard C).
Incorrect! Try again.
32What is the output of the following? int arr[] = {1, 2, 3}; printf("%d", 2[arr]);
A.Error
B.2
C.1
D.3
Correct Answer: 3
Explanation:
In C, arr[i] is *(arr + i). Due to commutativity of addition, *(arr + i) is the same as *(i + arr), which can be written as i[arr]. So 2[arr] accesses index 2, which is 3.
Incorrect! Try again.
33In 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)
Correct Answer: *(*(M + i) + j)
Explanation:
M + i points to row i. *(M + i) dereferences it to get the base address of row i. Adding j moves to column j. The outer * retrieves the value.
Incorrect! Try again.
34If 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.
Correct Answer: p is a pointer to int, q is an int.
Explanation:
The * binds only to the variable name p. To declare both as pointers, you would need int *p, *q;.
Incorrect! Try again.
35What 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.
Correct Answer: It is slower for large datasets ( vs ).
Explanation:
Linear search checks every element, making it inefficient for large arrays compared to Binary Search, which eliminates half the search space in each step.
Incorrect! Try again.
36Which format specifier is typically used to print a pointer address in C?
A.%p
B.%x
C.%u
D.%d
Correct Answer: %p
Explanation:
%p is the standard format specifier for printing a void * (address) in hexadecimal format.
Incorrect! Try again.
37When 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.
Correct Answer: We logically track the number of valid elements, though physical memory remains allocated.
Explanation:
Static arrays in C have fixed memory. 'Deletion' usually involves shifting elements to overwrite the target and decrementing a separate counter variable tracking the 'logical' size.
Incorrect! Try again.
38Consider char *str = "Hello";. What happens if you try str[0] = 'h';?
String literals like "Hello" are often stored in read-only memory sections. Modifying them via a pointer causes a write access violation.
Incorrect! Try again.
39What 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.
Correct Answer: To access the value at a memory address.
Explanation:
The indirection operator (dereference operator *) is used to access the data stored at the location pointed to by a pointer.
Incorrect! Try again.
40Which 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[]);
Correct Answer: func(ptr);
Explanation:
The function expects a pointer int *. Since ptr is already a pointer, you pass it directly.
Incorrect! Try again.
41If s is a 1D array of integers, which is equivalent to &s[0]?
A.s[0]
B.s
C.&s
D.*s
Correct Answer: s
Explanation:
The name of the array s decays to the address of the first element, which is &s[0].
Incorrect! Try again.
42Can 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.
Correct Answer: No, the size is fixed at compile time.
Explanation:
Static arrays are allocated on the stack (or data segment) with a fixed size determined at compile time. Dynamic allocation (malloc/free) is needed for resizable arrays.
Incorrect! Try again.
43What 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
Correct Answer: N - 1
Explanation:
For size N, indices range from 0 to N-1.
Incorrect! Try again.
44In 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.
Correct Answer: A matrix where the majority of elements are zero.
Explanation:
Sparse matrices are those where most elements are zero. Specialized array structures are often used to store them efficiently to save memory.
Incorrect! Try again.
45What is the associativity of the pointer operator * (dereference)?
A.Random
B.No associativity
C.Left to Right
D.Right to Left
Correct Answer: Right to Left
Explanation:
Unary operators in C, including * (dereference) and & (address-of), associate from right to left.
Incorrect! Try again.
46If 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.
Correct Answer: Yes, it compares memory addresses, but behavior is undefined if not in the same aggregate object.
Explanation:
Relational operators on pointers are strictly defined only if both pointers point to elements of the same array (or one past the last element). Comparing unrelated pointers is undefined behavior, though often technically executes based on memory layout.
Incorrect! Try again.
47What 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.
Correct Answer: To store a list of strings of varying lengths.
Explanation:
char *arr[] is frequently used to store a list of strings (like command line arguments argv). This is more memory efficient than a 2D char array for ragged text data.
Incorrect! Try again.
48Which header file is generally needed to use NULL?
A.<stdio.h> or <stddef.h>
B.<string.h> only
C.<math.h>
D.<conio.h>
Correct Answer: <stdio.h> or <stddef.h>
Explanation:
NULL is defined in several standard headers, including <stddef.h>, <stdlib.h>, and <stdio.h>.
Incorrect! Try again.
49When 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.
Correct Answer: The compiler infers the size from the number of initializers.
Explanation:
If the size is omitted during initialization, the compiler counts the number of elements provided in the brace list and sets the array size to that number.
Incorrect! Try again.
50What is the result of *&var?
A.The value of var.
B.Undefined.
C.The address of the pointer.
D.The address of var.
Correct Answer: The value of var.
Explanation:
& gets the address, and * dereferences that address immediately. They cancel each other out, returning the original value of var.