An array in C++ is basically a syntactic wrapper around a pointer and offset. An array variable can be passed to a same typed pointer argument.
array[i]
is the same as
*(array + i)
C++ doesn't do bounds checking on arrays for you the way Java or C# does. The principle is C++ is that the language doesn't do anything you didn't ask for. Checking if you are accessing an array out of bounds and throwing an exception adds overhead, which is unnecessary if you know that you will access in bounds.
When you access out of bounds memory that is still accessible by your application what you end up getting is uninitialized memory.
You could programatically get the correct number of elements in your array, or for the same code you could use an std::vector and check the size():
#include <vector>
std::vector<int> vals = {0, 1, 2, 3, 4};
for (int i=0, i < vals.size(), i+=2)
{
printf("%d ", array [i]);
}