Challenge - 5 Problems
String Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of String Pointer Arithmetic
What is the output of the following C code snippet?
DSA C
char *str = "hello"; printf("%c", *(str + 1));
Attempts:
2 left
💡 Hint
Remember that pointer arithmetic moves to the next character in the string.
✗ Incorrect
The pointer 'str' points to the first character 'h'. Adding 1 moves to the second character 'e'. Dereferencing gives 'e'.
❓ Predict Output
intermediate2:00remaining
String Length Calculation Using Pointer
What is the value of 'length' after running this code?
DSA C
char *s = "abcde"; int length = 0; while (*(s + length) != '\0') { length++; }
Attempts:
2 left
💡 Hint
Count characters until the null terminator '\0'.
✗ Incorrect
The loop increments length until it reaches the null character, counting all 5 characters.
🧠 Conceptual
advanced2:00remaining
Understanding String Memory Layout
Which statement correctly describes how the string "data" is stored in memory in C?
Attempts:
2 left
💡 Hint
Think about how arrays and strings are stored in C.
✗ Incorrect
In C, strings are arrays of characters stored consecutively in memory, ending with a null terminator.
🔧 Debug
advanced2:00remaining
Identify the Error in String Modification
What error occurs when running this code snippet?
DSA C
char *str = "hello"; str[0] = 'H';
Attempts:
2 left
💡 Hint
String literals are stored in read-only memory.
✗ Incorrect
String literals are stored in read-only memory; modifying them causes a segmentation fault.
🚀 Application
expert2:00remaining
Result of Pointer Increment on String Array
Given the code below, what is printed?
DSA C
char arr[] = "abc"; char *p = arr; printf("%c", *++p);
Attempts:
2 left
💡 Hint
The operator ++p increments the pointer before dereferencing.
✗ Incorrect
The pointer p is incremented to point to 'b', then dereferenced to print 'b'.
