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.22Medium
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.23Easy
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.
Q.24Medium
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.25Medium
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.
Advertisement
Q.26Medium
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.27Hard
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.28Hard
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.29Hard
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.30Hard
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.31Medium
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.32Hard
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.33Hard
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.34Medium
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.35Easy
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.36Easy
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.37Easy
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.38Easy
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).
Q.39Medium
Which function is used to find the first occurrence of a character in a string?
Answer: B
strchr() finds the first occurrence of a character. strrchr() finds the last occurrence. strstr() finds substrings.
Q.40Medium
What will be the output?
char arr[] = "ABC";
printf("%d", sizeof(arr));
Answer: B
sizeof includes the null terminator. "ABC" has 4 bytes (A, B, C, \0).