ProgrammingHard

Which statement about the value returned by strcmp("apple", "Apple") is guaranteed by the C standard?

  1. A. It is positive, because 'a' (97) compares greater than 'A' (65), though its exact magnitude is implementation-defined
  2. B. It is exactly 32, the difference between 'a' and 'A'
  3. C. It is zero, because the comparison ignores case
  4. D. It is negative, because 'A' is listed before 'a'

Correct answer: A. It is positive, because 'a' (97) compares greater than 'A' (65), though its exact magnitude is implementation-defined

The standard only promises a value less than, equal to or greater than zero. The sign is fixed by the first differing unsigned characters, but the magnitude is not specified.

More C Programming questions

Exams that ask this topic