1Which 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);
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 0.
B.It returns the last element.
C.It results in undefined behavior (Garbage value or crash).
D.It returns NULL.
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.Random order
D.Diagonal 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 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.
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 smallest element.
B.The middle 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.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.
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 - low) / 2;
C.mid = high - low / 2;
D.mid = (low * high) / 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 left.
B.Shifting elements to the right.
C.Swapping the first and last elements.
D.Only overwriting the element at that position.
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.ptr *int;
C.int *ptr;
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 value pointed to.
B.The memory address of the operand.
C.The size of the variable.
D.The type of the variable.
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 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.
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.1001
B.1004
C.1002
D.Unknown
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 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.
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 pointing to NULL.
C.A pointer to a function.
D.A pointer to an array.
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 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.
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.20
C.30
D.Garbage value
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 array of 10 integers.
B.An array of 10 pointers to integers.
C.A pointer to an integer.
D.A function returning a pointer.
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.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.
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.The sum of the addresses.
B.The number of bytes between them.
C.The number of elements between them.
D.Illegal operation.
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 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.
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.VOID
B.EMPTY
C.NULL
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 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.
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.delete ptr;
B.dealloc(ptr);
C.free(ptr);
D.remove(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.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.
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.1
B.2
C.3
D.Error
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.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.
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 requires sorted data.
B.It is harder to implement.
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.%d
B.%u
C.%x
D.%p
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 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.
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';?
Explanation: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 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.
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
B.*s
C.&s
D.s[0]
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, by assigning a new size.
C.No, the size is fixed at compile time.
D.Yes, if it is a global array.
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.N
B.N - 1
C.N + 1
D.
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 where the majority of elements are zero.
D.A matrix that cannot be accessed via pointers.
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.Left to Right
B.Right to Left
C.Random
D.No associativity
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.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.
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 store a list of strings of varying lengths.
C.To perform mathematical matrix multiplication.
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.<math.h>
C.<string.h> only
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 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.
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 address of var.
B.The value of var.
C.Undefined.
D.The address of the pointer.
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.
Incorrect! Try again.
Give Feedback
Help us improve by sharing your thoughts or reporting issues.