Best way to compare two int arrays of the same length? Best way to compare two int arrays of the same length? arrays arrays

Best way to compare two int arrays of the same length?


Use the standard memcmp function from <string.h>.

memcmp(a, b, sizeof(a)) == 0

whenever a and b are equal.


If you mean

int a[] = {0,1,0,0,1};int b[] = {0,1,0,0,1};int c[] = {1,1,0,0,1};

then

memcmp(a, b, sizeof(a)); /* returns zero for a match */memcmp(a, c, sizeof(a)); /* returns nonzero for no match */


Use a loop and compare the individual elements one after another.