ProgrammingVery hard

char d[8] = "#######"; strncpy(d, "ab", 5); int z = 0; for (int i = 0; i < 8; i++) if (d[i] == 0) z++; printf("%d", z); What is printed?

  1. A. 3
  2. B. 5
  3. C. 6
  4. D. 4

Correct answer: D. 4

strncpy copies 'ab' and pads the destination with zeros up to 5 bytes, so positions 2 to 4 become zero. Position 5 and 6 keep their '#', and position 7 was already the terminator.

More C Programming questions

Exams that ask this topic