A bounded copy can omit termination

A program tests three independent copies using the code below, with string.h included. For each row, source points to a valid string containing exactly the listed text, with one byte per displayed character. Enter its length as an exact integer in bytes and enter yes or no to indicate whether a contains a terminating null character after the copy.


C
char a[5];
strncpy(a, source, sizeof a);
Source textSource length (bytes)Terminator in a (yes/no)
oak
birch
aspen!

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Strings and string.h Questions: