Why does this for loop exit on some platforms and not on others?

前端 未结 14 2734
执念已碎
执念已碎 2020-12-12 09:00

I have recently started to learn C and I am taking a class with C as the subject. I\'m currently playing around with loops and I\'m running into some odd behaviour which I d

14条回答
  •  -上瘾入骨i
    2020-12-12 09:41

    Since you created an array of size 10, for loop condition should be as follows:

    int array[10],i;
    
    for (i = 0; i <10 ; i++)
    {
    

    Currently you are trying to access the unassigned location from the memory using array[10] and it is causing the undefined behavior. Undefined behavior means your program will behave undetermined fashion, so it can give different outputs in each execution.

提交回复
热议问题