Recall & Review
beginner
What function is used to find the length of a string in C?
The
strlen() function from string.h returns the number of characters in a string, excluding the null terminator.Click to reveal answer
beginner
How do you copy one string to another in C?
Use the
strcpy() function to copy the content of one string into another. Make sure the destination has enough space.Click to reveal answer
beginner
What does
strcmp() do in C?strcmp() compares two strings and returns 0 if they are equal, a negative value if the first is less, or a positive value if the first is greater.Click to reveal answer
beginner
How can you concatenate two strings in C?
Use
strcat() to append one string to the end of another. The destination string must have enough space to hold the result.Click to reveal answer
intermediate
Why must you be careful with string operations in C?
Because C strings are arrays of characters ending with a null byte, you must ensure enough memory is allocated to avoid buffer overflows and undefined behavior.
Click to reveal answer
Which function returns the length of a string in C?
✗ Incorrect
strlen() counts characters until the null terminator.What does
strcmp() return when two strings are equal?✗ Incorrect
strcmp() returns 0 if strings are exactly the same.Which function appends one string to another in C?
✗ Incorrect
strcat() adds the second string to the end of the first.What must you ensure before using
strcpy()?✗ Incorrect
The destination must have enough space to hold the copied string.
What character marks the end of a string in C?
✗ Incorrect
Strings in C end with the null character '\0' to mark their end.
Explain how to safely copy and concatenate strings in C.
Think about destination size and string endings.
You got /4 concepts.
Describe what
strcmp() returns and how to interpret its result.Compare two strings alphabetically.
You got /3 concepts.