can size of array be determined at run time in c?

前端 未结 6 1979
日久生厌
日久生厌 2020-11-29 08:24

As I know, an array needs to have a specific size before compiling time in c.

I wonder why this code still works?

int s;
printf(\"enter the array si         


        
6条回答
  •  一生所求
    2020-11-29 09:00

    If you need to allocate an array with dynamic size, you have to get it from the heap, with malloc().

    int *a = malloc(sizeof(int) * s)
    

提交回复
热议问题