I have enough stack space for my array, so why does this loop fail?

后端 未结 3 381
太阳男子
太阳男子 2021-01-16 05:56
int width = 2560;
int height = 1440;
int frameBuffer[width*height];
for (int i = 0; i < width*height; ++i)
    frameBuffer[i]=i;

This code locks

3条回答
  •  野的像风
    2021-01-16 06:29

    the number of elements the array is going to hold, must be a constant value, since arrays are blocks of non-dynamic memory whose size must be determined before execution. In order to create arrays with a variable length dynamic memory is needed

    use int frameBuffer[2560*1440];

提交回复
热议问题