This is an out-of-bound read, it's undefined behavior. numbers only has 4 elements, that means you can only legally access index 0 to 3. But your while loop doesn't do that bound check. Reading an element with an index outside of the array capacity will read a garbage data, if that garbage data happens to be zero, your "while loop" will stop. But that's not always the case. IOW, you're while loop condition relies on a random undefined value. You can just use a for loop like this to reliably stop the iteration: int main() { int numbers[]{23, 45, 76, 66}; int i; for (i = 0; i < 4; i++) { cout << numbers[i] << endl; } return 0; } This is safe because it will never perform an out-of-bound read.