KKG KKG - 1 year ago 100
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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download