Machine-translated by Google. Questions are authored in English.
Top

Discussion

What will the given C code do?

int memcmp(const void *str1, const void *str2, size_t n)

 

  • A.compares the first n bytes of str1 and str2
  • B.copies the first n bytes of str1 to str2
  • C.copies the first n bytes of str2 to str1
  • D.invalid function

Answer: A

Correct answer: compares the first n bytes of str1 and str2

memcmp compares the first n bytes of the two objects, returning a negative, zero or positive value like strcmp. It copies nothing, and unlike the str functions it takes no notice of null bytes - it compares exactly n bytes whatever they contain.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.