I'm having some issues comparing two arrays:
int array[3] = {23, 14, 1};
if (array == {12, 43, 1}) {
// Do something
}
The error I get is:
error: expected primary-expression before '{' token
if (array == {12, 43, 1}) {
^
error: expected ')' before '{' token
I also tried this:
bool compareArrays(int firstArray[], int secondArray[], int length) {
for (int i = 0; i < length; i++) {
if (firstArray[i] != secondArray[i]) {
return false;
}
}
return true;
}
But I get another error when I do so:
if (compareArrays(array, {12, 43, 1}, 3)) {
// Do something
}
error: cannot convert '<brace-enclosed initializer list>' to 'int*' for argument '2' to 'bool compareArrays(int*, int*, int)'
How can I solve the problem ? Thanks in advance.