For Example:
array[2]={1,2};
myInt=5;
if (array[myInt-6]==2)
cout << true << endl;
else
cout << false << endl;
The referenced value in the array in the if statement is clearly out of bounds. When I compile and run this I get false outputted which makes sense as the condition is not true, but I’m wondering why theres no error outputted.
Because undefined behavior is undefined. Anything can happen, including appearing to work.
A diagnostic isn’t required of the compiler nor the runtime. You have to take care of bound checking by yourself.