ProgrammingHardTCS NQT · Infosys

Which statement about the return value of strcmp is true?

  1. A. strcmp returns exactly -1, 0 or 1
  2. B. strcmp returns a negative, zero or positive value, and the standard fixes only the sign
  3. C. strcmp returns the length difference of the two strings
  4. D. strcmp is undefined when the strings are equal

Correct answer: B. strcmp returns a negative, zero or positive value, and the standard fixes only the sign

The standard promises only the sign of the result, so code must test with less than zero and greater than zero. Assuming exactly -1, 0 or 1 breaks on some platforms.

More C Programming questions

Exams that ask this topic