I'm learning C++, doing some easy examples, and found this odd behavior. When filling the elements of an array of integers, if any of the elements is set to something greater than 2147483647 (which I believe is the maximum integer value?), the rest of the elements in the array are set to that exact number, every one of them.
I understand that if one element goes beyond its type limit, the compiler caps it to that limit, but I can't get why it does the same thing with the other items, without even asking the user to fill them.
Here's a simple test I've run:
#include <iostream>
using namespace std;
int main()
{
int test[5];
int num = 0;
for (int i=0; i<5; i++)
{
cout << "Enter the number in position " << i << endl;
cin >> num;
test[i] = num;
}
cout << "Values in the array: " <<endl;
for (int i=0; i<5; i++)
cout << test[i] << endl;
}
Thanks for reading, commenting, and helping!