My question is pretty straightfoward: why can I assign a value that goes out of bounds to an array like this, but not with the {} operator:
int arr[2];
arr[2] = 2;
for(int num{0}; num < 3; num++)
cout << arr[num] << endl;
But when I do this I get an error right from the start:
int arr[2] {1,2,3};
Now I know that assigning a value beyond the scope of the array may cause an undefinied behavior, as this questions has clarified to me:
Accessing an array out of bounds gives no error, why?
But why can't I go beyond the arrays' limit in the second case? Even though it is wrong - And I don't intend to do it - I'd like to know the difference in these cases.