Why is there an infinite loop in my program?

后端 未结 5 744
再見小時候
再見小時候 2021-01-04 16:15
int main(void)
{
    int i;
    int array[5];

    for (i = 0; i <= 20; i++)
    array[i] = 0;

    return 0;
}

Why is the above code stuck in a

5条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-04 16:35

    You are invoking undefined behaviour by overwriting beyond the memory you are allowed. So anything can happen.

    Most likely, it's overwriting the loop counter.

提交回复
热议问题