-4

For memecmp(), the third parameter is size_t(unsigned). But when we pass third parameter as -1 returns always 0, eventhough the memory block pointed by first and second parameters are different?

geek
  • 47
  • 1
  • 9

1 Answers1

0

What are you comparing? memcmp() returns 0 if the contents in the two memory blocks are equal.

M. Shaw
  • 1,742
  • 11
  • 15
  • In memcmp(), third parameter tells the size(size_t) of the memory blocks to be compared between 1 and 2. But if we pass the third parameter as -1 which is a negative value. And as the third parameter is -1 which wraps its value to max value. In case of 32 bit system the value will become as 0xffffffff. But in my case the value which memcmp() return is zero. So can you please explain me how this is happening also please let me know if there is any documented reference which justify the same – geek Aug 21 '15 at 09:14
  • @user3782944 As I said, `memcmp(a, b, num)` returns `0` if the memory block pointed by `a` and `b` are equal. – M. Shaw Aug 21 '15 at 09:33
  • But memory block pointed by a and b are different in my case. – geek Aug 24 '15 at 03:28