0
0
Cprogramming~20 mins

String handling using library functions - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
String Handling Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of string concatenation with strcat
What is the output of this C program?
C
#include <stdio.h>
#include <string.h>

int main() {
    char str1[20] = "Hello";
    char str2[] = " World";
    strcat(str1, str2);
    printf("%s", str1);
    return 0;
}
ACompilation error
BHello
CHello World
D WorldHello
Attempts:
2 left
💡 Hint
Remember that strcat appends the second string to the first one.
Predict Output
intermediate
2:00remaining
Result of strlen on a string
What is the output of this C program?
C
#include <stdio.h>
#include <string.h>

int main() {
    char str[] = "C programming";
    printf("%zu", strlen(str));
    return 0;
}
A12
B14
CCompilation error
D13
Attempts:
2 left
💡 Hint
strlen counts characters before the null terminator.
Predict Output
advanced
2:00remaining
Output of strcmp comparing two strings
What is the output of this C program?
C
#include <stdio.h>
#include <string.h>

int main() {
    char s1[] = "apple";
    char s2[] = "apples";
    int result = strcmp(s1, s2);
    printf("%d", result);
    return 0;
}
A0
BA negative number
CA positive number
DCompilation error
Attempts:
2 left
💡 Hint
strcmp returns negative if first string is less than second.
Predict Output
advanced
2:00remaining
Behavior of strcpy with overlapping strings
What is the output of this C program?
C
#include <stdio.h>
#include <string.h>

int main() {
    char str[] = "overlap";
    strcpy(str + 2, str);
    printf("%s", str);
    return 0;
}
AUndefined behavior (may crash or print garbage)
Bovoverlap
Claplap
Doverlap
Attempts:
2 left
💡 Hint
strcpy does not support overlapping source and destination.
🧠 Conceptual
expert
2:00remaining
Which function safely copies strings with buffer size limit?
Which of the following C functions is designed to copy strings safely by limiting the number of characters copied to avoid buffer overflow?
Astrncpy
Bstrcpy
Cstrcat
Dstrcmp
Attempts:
2 left
💡 Hint
One function lets you specify the maximum number of characters to copy.