Bird
0
0
DSA Cprogramming~20 mins

String Basics and Memory Representation in DSA C - Practice Problems & Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
String Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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));
Ae
Bh
Co
Dl
Attempts:
2 left
💡 Hint
Remember that pointer arithmetic moves to the next character in the string.
Predict Output
intermediate
2: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++;
}
A4
B5
C6
D0
Attempts:
2 left
💡 Hint
Count characters until the null terminator '\0'.
🧠 Conceptual
advanced
2:00remaining
Understanding String Memory Layout
Which statement correctly describes how the string "data" is stored in memory in C?
ACharacters are stored backwards in memory ending with '\0'.
BCharacters are stored in random memory locations with a pointer array pointing to each.
CThe string is stored as a single integer representing all characters.
DEach character is stored in consecutive memory locations followed by a null terminator '\0'.
Attempts:
2 left
💡 Hint
Think about how arrays and strings are stored in C.
🔧 Debug
advanced
2:00remaining
Identify the Error in String Modification
What error occurs when running this code snippet?
DSA C
char *str = "hello";
str[0] = 'H';
ASegmentation fault (attempt to modify read-only memory)
BNo error, output is 'Hello'
CCompilation error: cannot assign to str[0]
DRuntime error: null pointer dereference
Attempts:
2 left
💡 Hint
String literals are stored in read-only memory.
🚀 Application
expert
2: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);
A\0
Ba
Cb
Dc
Attempts:
2 left
💡 Hint
The operator ++p increments the pointer before dereferencing.