What is the time complexity of accessing an element at index 5 in an array?
Answer: A
Array access by index is O(1) because arrays use contiguous memory allocation, allowing direct access via base address + offset calculation.
Q.402Medium
Which of the following correctly declares and initializes a 2D array?
Answer: C
Both syntax forms are valid in C. Elements can be provided in nested braces or as a linear list, and they fill row by row.
Q.403Medium
What is the relationship between array name and pointer in C?
Answer: A
Array names decay to pointers to the first element in expressions, but they are not truly pointer variables. The array name cannot be reassigned.
Q.404Medium
If str = "Hello", what is the value of str[5]?
Answer: A
"Hello" has 5 characters, so valid indices are 0-4. Index 5 contains the null terminator '\0' that marks the end of the string.
Q.405Easy
What does strlen() function return for the string "C2025"?
Answer: A
strlen() counts characters before the null terminator. "C2025" has 5 characters, so strlen returns 5. The null terminator is not counted.
Advertisement
Q.406Medium
In a 2D array int matrix[4][5], which statement about memory layout is true?
Answer: A
C uses row-major order for 2D arrays. matrix[0][0], matrix[0][1]...matrix[0][4], matrix[1][0]... are stored sequentially in memory.
Q.407Medium
What is the output of sizeof(arr)/sizeof(arr[0]) when arr is declared as int arr[10]?
Answer: A
This expression calculates array length. sizeof(arr) gives total bytes (40 on 32-bit system), sizeof(arr[0]) gives bytes per element (4), so 440=10.
Q.408Medium
Which string function modifies the original string in-place?
Answer: D
Both strtok() (modifies by replacing delimiters with '\0') and strcpy() (copies and overwrites destination) modify strings in-place.
Q.409Hard
Consider: int arr[3][4][5]. What is the size of arr[0][0]?
Answer: A
arr[0][0] is a 1D array of 5 integers. Each int is 4 bytes, so total is 5×4=20 bytes.
Q.410Hard
Which of the following is true about strcpy(dest, src)?
Answer: B
strcpy() doesn't check dest buffer size, making it unsafe. It can cause buffer overflow if src is larger than dest. Modern compilers recommend strncpy() or strlcpy().
Q.411Hard
What is the main difference between char arr[] = "Test" and char *ptr = "Test"?
Answer: A
arr creates a modifiable array copy of the string. ptr points to a string literal (read-only in memory). Modifying *ptr leads to undefined behavior.
Q.412Hard
If ptr is a pointer to int array and ptr = arr, what does ptr[3] represent?
Answer: D
ptr[3] is equivalent to arr[3] and accesses the element at address *(ptr+3). For int*, ptr+3 moves 12 bytes (3×4 bytes) in memory.
Q.413Medium
What happens when you try to modify a string literal in C?
Answer: C
String literals are stored in read-only memory. Attempting modification causes undefined behavior (often segmentation fault). This is why char *str = "text"; str[0]='T'; is dangerous.
Q.414Hard
What is the correct way to safely copy strings in modern C?
Answer: B
strncpy with buffer size check and explicit null termination is the standard safe approach. Option A lacks bounds checking; C and D have issues with null termination.
Q.415Hard
In the declaration int *arr[10], what is arr?
Answer: A
int *arr[10] declares an array of 10 pointers to int (subscript binds tighter than dereference). Use int (*arr)[10] for pointer to array.
Q.416Medium
What is the time complexity of inserting an element at the beginning of an unsorted array?
Answer: B
Inserting at the beginning requires shifting all n elements one position right, making it O(n). Insertion at the end is O(1) if space exists.
Q.417Easy
What will be the output of the following code?
int arr[] = {1, 2, 3, 4, 5};
printf("%d", *(arr + 3));
Answer: A
arr + 3 points to the 4th element (index 3) which is 4. Dereferencing gives 4.
Q.418Easy
Which of the following correctly declares a 2D array of strings?
Answer: C
Both are valid ways to declare arrays of strings. Option A creates a 2D array, Option B creates an array of pointers to strings.
Q.419Easy
What is the output of strlen("Hello") in C?
Answer: A
strlen() returns the length of the string excluding the null terminator. "Hello" has 5 characters.
Q.420Easy
How many bytes are allocated by: int arr[10][20];?
Answer: C
10 rows × 20 columns × 4 bytes per int = 800 bytes (assuming 4-byte integer).