ProgrammingHard

int r = strcmp("abc", "abd"); What can be said about r according to the C standard?

  1. A. It is exactly -1
  2. B. It is zero, since only the first two letters are compared
  3. C. It is negative, since 'c' is less than 'd'
  4. D. It is positive, since the strings have equal length

Correct answer: C. It is negative, since 'c' is less than 'd'

The standard guarantees only the sign of strcmp's result. The first differing characters are c and d, so the sign is negative.

More C Programming questions

Exams that ask this topic