What does strcmp() exactly return in C?

From the cppreference.com documentation

int strcmp( const char *lhs, const char *rhs );

Return value

  • Negative value if lhs appears before rhs in lexicographical order.
  • Zero if lhs and rhs compare equal.
  • Positive value if lhs appears after rhs in lexicographical order.

As you can see it just says negative, zero or positive. You can’t count on anything else.

The site you linked isn’t incorrect. It tells you that the return value is < 0== 0 or > 0 and it gives an example and shows it’s output. It doesn’t tell the output should be 111.

Leave a Comment