What will happen if in a C program you assign a value to an array element whose subscript exceeds the size of array?
Answer: C
Correct answer: The program may crash if some important data gets overwritten.
C does no bounds checking. Writing past the end of an array simply stores to whatever address the index computes to, so the effect depends on what happens to be there: often nothing visible, sometimes a corrupted variable, sometimes a crash when a return address or a pointer is overwritten. The compiler cannot generally report it, the element is not zeroed, and the array certainly does not grow.
Please log in or register to report this question.