Trying to access array element in loop causes segmentation fault, why?

后端 未结 2 590
温柔的废话
温柔的废话 2021-01-25 03:16

I am trying to create a two dimensional array, which has either 1 or 0 randomly assigned to each coordinate. It works just fine until it gets to the coordinates [20][3]. After t

2条回答
  •  说谎
    说谎 (楼主)
    2021-01-25 03:39

    You're running past the bounds of the array. That's undefined behaviour in C, and is manifesting itself as a crash.

    Change i <= x to i < x etc, or increase the grid size.

提交回复
热议问题