ProgrammingModerate

char buf[] = "abc\n"; buf[strcspn(buf, "\n")] = '\0'; printf("%zu", strlen(buf)); What is printed?

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

Correct answer: A. 3

strcspn returns the index of the newline, 3, and the terminator replaces it. The length is therefore 3 and the newline is gone.

More C Programming questions

Exams that ask this topic