ProgrammingVery hard

char buf[10]; strncpy(buf, "abc", 10); int zeros = 0; for (int i = 0; i < 10; i++) if (buf[i] == 0) zeros++; printf("%d", zeros); What is printed?

  1. A. 6
  2. B. 8
  3. C. 1
  4. D. 7

Correct answer: D. 7

strncpy copies 'abc' and then pads the remaining 7 bytes with zeros, so there are 7 zero bytes in total.

More C Programming questions

Exams that ask this topic