Practice mode C Language

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.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.