What does strcmp(s1, s2) return when s1 comes before s2 in lexicographic order?
Correct answer D. A negative integer
Explanation
strcmp compares the strings character by character as unsigned char values and returns a negative value if s1 sorts first, zero if they are equal and a positive value if s1 sorts after. The standard does not promise -1 or 1, only the sign, so test with 0. Comparing strings with == compares pointer addresses, not contents.
Answer checked How we write and check questions
Discussion