It isnt working properly cauz if I change in a1 3rd elemet it keep printing out equals..my task is to compare all elements in the arrays then print out true if all are same or not if there is missmatch
The function equality() should not assume it knows the length of the arrays. Instead pass the length as a parameter.
The code of Thomas1965 should work if adjusted accordingly.
Or, since you have included the <algorithm> header,
1 2 3 4
bool equality(int a[], int b[], unsignedint size)
{
return std::equal( a, a+size, b);
}
Error 1 error C4996: 'std::_Equal1': Function call with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators'
output of your code
my task is to compare all elements in the arrays then print out true if all are same or not if there is missmatch
There is no point is comparing all the elements once you find a mismatch. Once you find a mismatch, you know for certain the arrays are not equal. In fact, it is inefficient to do otherwise. Thomas1965's code correctly exits when the first mismatch is found.