Which function is safe to use for string concatenation with size limiting?
Answer: B
strncat() allows specifying maximum characters to concatenate, preventing buffer overflow. strcat() has no size limit.
Q.82Medium
In C, what happens when you pass an array to a function?
Answer: B
Arrays decay to pointers when passed to functions. Only the address of the first element is passed, not a copy of entire array.
Q.83Easy
What is the correct way to declare and initialize a string in C?
Answer: B
Option B shows two valid ways: pointer to string literal or character array. Option A is wrong (single char), C is wrong (no String type in C).
Q.84Medium
What does the expression *(arr + 3) represent for an integer array?
Answer: B
arr + 3 points to the 4th element (0-indexed). Dereferencing with * gives its value, equivalent to arr[3].
Q.85Medium
Which of the following operations is NOT allowed on array names in C?
Answer: B
Array names are non-modifiable lvalues. You cannot use ++ on them. However, individual elements can be accessed and modified.
Advertisement
Q.86Medium
In a string with escape sequences like "Hello\nWorld", how many characters are counted by strlen()?
Answer: B
\n is a single character (newline). 'Hello' = 5 + \n = 1 + 'World' = 5, total = 11 characters (not counting null terminator).
Q.87Hard
What is the relationship between pointer arithmetic and array indexing in C?
Answer: B
C standard defines arr[i] as *(arr + i). Both notations access the same memory location and perform identically.
Q.88Hard
What potential issue exists with this code: char *ptr = "Hello"; ptr[0] = 'h';?
Answer: B
String literals are stored in read-only memory. Attempting to modify them causes undefined behavior or segmentation fault at runtime.
Q.89Hard
For a 3D array int arr[2][3][4], what is arr[1][2][3] equivalent to?
Answer: B
In row-major order: address = base + (i*m*n + j*n + k) where m=3, n=4. So arr[1][2][3] = base + 1*12 + 2*4 + 3 = base + 23.
Q.90Easy
What is the output of: int arr[] = {10, 20, 30}; printf("%d", *(arr+1));?
Answer: B
arr+1 points to second element (arr[1]). Dereferencing gives value 20.
Q.91Hard
In string handling, what is the difference between fgets() and gets()?
Answer: C
gets() has no buffer overflow protection and was removed in C11. fgets(str, size, stdin) is the safer alternative with size limiting.
Q.92Easy
What will be the size in bytes of int arr[5] on a 32-bit system?
Answer: C
On 32-bit systems, int is typically 4 bytes. 5 elements × 4 bytes = 20 bytes total.
Q.93Hard
Which of the following correctly declares a pointer to an array (not array of pointers)?
Answer: B
Parentheses change precedence. int (*ptr)[5] is pointer to array of 5 ints. int *arr[5] is array of 5 pointers.
Q.94Medium
What is the output of: char str[20]; scanf("%s", str); when input is 'Hello World'?
Answer: B
%s format specifier stops reading at whitespace. To read entire line including spaces, use fgets() or %[^\n].
Q.95Hard
In what scenario would you use memcpy() instead of strcpy()?
Answer: B
strcpy() assumes null-terminated strings. memcpy() copies exact number of bytes, suitable for binary data or embedded nulls.
Q.96Medium
What is the correct syntax to pass a 2D array to a function?
Answer: B
First dimension can be omitted, but second must be specified: int arr[][4]. Option C (int **arr) is not equivalent - it's pointer to pointer.
Q.97Hard
What does the strspn() function do?
Answer: B
strspn(str, charset) returns length of initial segment of str containing only characters from charset. Useful for token parsing.
Q.98Medium
For char arr[5] = {'a', 'b', 'c', 'd', 'e'}, is this a valid string?
Answer: B
String functions expect null terminator. This array has no '\0', so it's a character array but NOT a proper string for str* functions.
Q.99Easy
Consider the following code:
char str[] = "HELLO";
int len = 0;
while(str[len] != '\0') {
len++;
}
printf("%d", len);
What will be the output?
Answer: A
The string "HELLO" has 5 characters. The while loop counts characters until it encounters the null terminator '\0'. The output will be 5. The null terminator is not counted in the length.