Practice mode C Language

Which function should be used to copy bytes between two memory regions that may overlap?

Correct answer D. memmove()

Explanation

memmove behaves as if the bytes were first copied to a temporary buffer, so it gives the correct result even when source and destination overlap, as when shifting array elements. memcpy has undefined behaviour for overlapping regions, although it may be slightly faster. strcpy is for null-terminated strings, and memset fills memory with one byte value rather than copying.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.