I have to check equality of two arrays(1-D) with integer elements.
I understand that there is no direct comparison way. So i'm doing basic iteration and checking for equality of each element.
for ( int i = 0 ; i < len ; i++) {
// Equality check
What is the most efficient way to test equality of arrays in C ? Can i get away with loops(for ..) somehow ?
Use memcmp
function to compare two arrays of equal length.
int a = memcmp(arr1, arr2, sizeof(arr1));
if(!a)
printf("Arrays are equal\n");
else
printf("Arrays are not equal\n");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With