ProgrammingVery hard

char s[] = "abcdef"; memmove(s + 2, s, 4); printf("%s", s); What is printed?

  1. A. ababab
  2. B. ababcd
  3. C. abcdef
  4. D. ababcdef

Correct answer: B. ababcd

memmove behaves as if the source were copied to a temporary first, so 'abcd' lands intact at positions 2 to 5. A forward byte-by-byte copy, memcpy style, would overwrite its own source and give 'ababab'.

More C Programming questions

Exams that ask this topic