There have been other question/answers on negative array in C in the forum, but i would request the answer to these for a 32-bit compiler :
If we have an array defined int test_array[5] = {1,2,3,4,5};
then what should following statements return
test_array[20], test_array[-2], test_array[-32764], test_array[4294967700](value greater than what 32 bit can accommodate), *(a-32764) etc
Does the compiler force any fixed value to be returned in case index go beyond its declared range ?
Accessing an array beyond its bounds results in Undefined Behavior(UB).
An
-veindex is not an valid index and results in Undefined Behavior.An Undefined Bheavior means anything can happen literally, If you are lucky your program will crash and the problem gets detected, If you are unlucky the code works fine all along and all hell breaks loose some day.
So, always avoid writing any code which causes an Undefined Behaivor.
NO
The programmer has to take care of this. The Standard does not need the compiler to give you any indication/warning for this.The standard just defines it as an UB.
Furthermore the standard identifies all of the following scenarios to cause Undefined Behavior: