KKG KKG - 11 months ago 78
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.

Answer Source

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.