ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
#include <stdio.h>
#include <string.h>
int main(void) {
    printf("%d", strcmp("apple", "apricot") < 0);
}
  1. A. 0
  2. B. 2
  3. C. 3
  4. D. 1

Correct answer: D. 1

apple and apricot share the prefix ap, then p (112) is less than r (114), so apple sorts first and the comparison is true.

More C Programming questions

Exams that ask this topic