Just because you allocate a 4 x 4 array (16 elements) that doesn't mean you have to use them - the compiler doesn#t know (or care) that you don't, as long as all the elements you try a=to access are within the 4 x 4 block:
0, 0 0, 1 0, 2 0, 3
1, 0 1, 1 1, 2 1, 3
2, 0 2, 1 2, 2 2, 3
3, 0 3, 1 3, 2 3, 3
And the reason it doesn't care is simple: it has no idea if you have finished your code, or you have written a bit of it, are testing that it works, and will expand the number of elements you use later with additional code when it's OK so far. That's a reasonable way to do things - I do it all the time, write a bit, check it, write some more, check that, repeat.
So yes, your code could be simpler:
int arr[4];
int a, b;
int temp;
cout << "Enter four numbers: \n";
for (a=0; a<4; a++)
{
cin >> arr[a];
}
cout << endl;
cout <<"Even numbers: \n";
for (a=0;a<4;a++)
{
if (arr[a]%2==0)
{
cout << arr[a]<<endl;
}
}
cout << endl;
But it's perfectly valid to write more complex code that does the same thing!