Recall & Review
beginner
What is a string in C?
A string in C is an array of characters ending with a special character called the null terminator '\0' which marks the end of the string.
Click to reveal answer
beginner
Why do C strings end with a null terminator '\0'?
The null terminator '\0' tells functions where the string ends in memory since C does not store string length separately.
Click to reveal answer
beginner
How is a string stored in memory in C?
A string is stored as a sequence of characters in consecutive memory locations, followed by a null terminator '\0'.
Click to reveal answer
intermediate
What happens if a string in C does not have a null terminator?
Without a null terminator, functions that process strings may read beyond the intended end, causing undefined behavior or errors.
Click to reveal answer
beginner
How can you declare and initialize a string in C?
You can declare a string as a char array with initialization like: char str[] = "hello"; which automatically adds the null terminator.
Click to reveal answer
What character marks the end of a string in C?
✗ Incorrect
The null terminator '\0' marks the end of a string in C.
How is a string stored in memory in C?
✗ Incorrect
Strings in C are stored as contiguous characters followed by a null terminator.
What happens if a C string is missing the null terminator?
✗ Incorrect
Without a null terminator, string functions may read memory beyond the string causing undefined behavior.
Which of these is a correct way to declare a string in C?
✗ Incorrect
char str[] = "hello"; declares a char array initialized with the string and null terminator.
What is the size in memory of the string "cat" in C?
✗ Incorrect
The string "cat" has 3 characters plus 1 null terminator, so 4 bytes total.
Explain how strings are represented and stored in memory in C.
Think about how C knows where the string ends.
You got /4 concepts.
Describe the importance of the null terminator in C strings and what can go wrong if it is missing.
Consider how string functions find the string length.
You got /3 concepts.
