ProgrammingHard

char buf[8] = "12345"; buf[strlen(buf) - 1] = '\0'; printf("%s", buf); What is printed?

  1. A. 12345
  2. B. 1235
  3. C. 5
  4. D. 1234

Correct answer: D. 1234

strlen is 5, so the index 4 holds the last digit, which is replaced by the terminator. The string becomes 1234.

More C Programming questions

Exams that ask this topic