PRACTICE • LEARN • GROW
Module 8: Strings - Final Quiz MCQs
Solve topic-wise placement questions and improve your skills.
Module 8: Strings - Final Quiz Progress
0 of 8 completed
0%
Topic Track
You are viewing MCQs in preview mode. Log in to select options, submit answers, and track your progress.
Log In to Answer
1
What is the terminating character that marks the end of all valid C strings in memory, and what is its ASCII code?
A.
'\n' with ASCII 10
B.
'\0' with ASCII 0
C.
EOF with ASCII -1
D.
' ' with ASCII 32
Explanation & Key
Correct Answer:
2
What happens when the following code attempts to modify a string literal?
#include <stdio.h>
int main() {
char *s = "Ready";
s[0] = 'r';
printf("%s", s);
return 0;
}
A.
Prints
ready
B.
Compile-time error
C.
Undefined Behavior / Segmentation Fault at runtime
D.
Memory leak
Explanation & Key
Correct Answer:
3
What is the output of the following comparison between sizeof and strlen?
#include <stdio.h>
#include <string.h>
int main() {
char str[] = "ReadyToGo";
printf("%zu %zu", sizeof(str), strlen(str));
return 0;
}
A.
9 9
B.
10 9
C.
9 10
D.
8 9
Explanation & Key
Correct Answer:
4
What does
strcmp(str1, str2) return when both strings are identical character-by-character?
A.
1
B.
0
C.
-1
D.
true
Explanation & Key
Correct Answer:
5
Why is standard
strcpy(dest, src) considered dangerous in security audits?
A.
It converts characters to lowercase automatically
B.
It performs no destination buffer bounds checking, making it a primary cause of buffer overflow vulnerabilities
C.
It leaks heap memory
D.
It does not copy the null terminator
Explanation & Key
Correct Answer:
6
What is the output of passing a non-null-terminated char array to strlen()?
char c[3] = {'C', 'O', 'D'};
printf("%zu", strlen(c));
A.
3
B.
0
C.
Undefined Behavior — strlen reads past array bounds until it happens upon a zero byte
D.
Compile error
Explanation & Key
Correct Answer:
7
What requirement must be met before calling
strcat(dest, src)?
A.
Both strings must have identical lengths
B.
dest must already contain a valid null-terminated string and have sufficient allocated buffer space for the combined result plus '\0'
C.
dest must be allocated with calloc()
D.
src must be empty
Explanation & Key
Correct Answer:
8
What is printed by pointer arithmetic on this string?
#include <stdio.h>
int main() {
char s[] = "ReadyToGo";
printf("%s", s + 5);
return 0;
}
A.
ToGo
B.
Ready
C.
yToGo
D.
ReadyToGo
Explanation & Key
Correct Answer:
Question Palette
Answered
Current
Not Attempted
Wrong