If the arrays are so small, I would just take a brute force approach and skip both arrays:
for (int i=0;i<4;++i) { for (int j=0;j<4;++j) { if (a[i] == b[j]) {
If you are going to deal with large arrays, you can, however, consider a better algorithm, since it is O (n ^ 2).
If, for example, one of your arrays is sorted, you can check for matches faster, especially as the length of the array increases. I would not worry about anything more complicated, though, if your arrays will always always contain several elements.
source share