KKG KKG - 6 months ago 58
C++ Question

c++ memcpy read memory

I'm trying to use memcpy to read memory.

BYTE test[] = {0x01};
BYTE test2[] = {0x00};
memcpy (test, test2, sizeof(test));
if (test == test2){

Why the test and test2 always different?

Thanks for your help.


You're comparing addresses of test and test2. Use memcmp instead.

Your code is equivalent to

if (&test[0] == &test2[0]){

Changing it to

if (memcmp(test, test2, sizeof(test)) == 0)

should work as you expected.