ProgrammingHard

char d[4]; char s[] = "abc"; strncpy(d, s, sizeof d - 1); d[sizeof d - 1] = '\0'; printf("%s", d); What is printed?

  1. A. abc
  2. B. ab
  3. C. abcd
  4. D. abx

Correct answer: A. abc

strncpy copies at most three characters, and the explicit terminator at the last slot makes the string complete.

More C Programming questions

Exams that ask this topic