ProgrammingHard

char *a = "ab", *b = "ab"; printf("%d", strcmp(a, b) == 0); What is printed?

  1. A. 0
  2. B. undefined
  3. C. 1
  4. D. 2

Correct answer: C. 1

strcmp compares the characters, which are equal here, so the result is 0 and the comparison with 0 is true. The == operator would compare addresses, which is not what this code does.

More C Programming questions

Exams that ask this topic