How to check if two arrays are equal or not in C

1 Answer

0 votes
#include <stdio.h>
#include <string.h>
  
int main(void) {
    int arr1[] = { 5, 7, 98 };
    int arr2[] = { 5, 7, 98 };
      
    if (memcmp(arr1, arr2, 3 * sizeof(int)) == 0) {
        printf("Arrays are equal");
    } else {
        printf("Arrays are not equal");
    }
    
    return 0;
}
  
  
  
/*
run:
  
Arrays are equal
  
*/

 



answered Dec 24, 2020 by avibootz
edited Dec 25, 2020 by avibootz

Related questions

1 answer 183 views
3 answers 259 views
1 answer 124 views
1 answer 147 views
1 answer 279 views
...