ProgrammingHard

char *s = "x"; char t[2] = {'y', '\0'}; int r = strcmp(s, t); What does r look like?

  1. A. Negative, since 'x' comes before 'y'
  2. B. Positive, since 'x' is larger in ASCII
  3. C. Exactly 0, because both strings have one character
  4. D. Undefined, since t is not a literal

Correct answer: A. Negative, since 'x' comes before 'y'

The first characters are 'x' and 'y'. In ASCII 'x' is 120 and 'y' is 121, so the result is negative.

More C Programming questions

Exams that ask this topic