0
0
Cprogramming~5 mins

Common string operations - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
Astrcpy()
Bstrlen()
Cstrcmp()
Dstrcat()
What does strcmp() return when two strings are equal?
AThe length of the strings
BA negative number
CA positive number
DZero
Which function appends one string to another in C?
Astrcat()
Bstrcpy()
Cstrlen()
Dstrcmp()
What must you ensure before using strcpy()?
AThe destination has enough space
BThe strings are the same length
CThe source string is empty
DThe strings are null-terminated
What character marks the end of a string in C?
ASpace character
BNewline character
CNull character '\0'
DTab character
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.