can we give size of static array a variable

前端 未结 6 472
余生分开走
余生分开走 2021-01-04 11:21

hello every one i want to ask that i have read that we can declare dynamic array only by using pointer and using malloc or newlike

int * array = new int[strl         


        
6条回答
  •  温柔的废话
    2021-01-04 12:19

    What you have written works in C99. It is a new addition named "variable length arrays". The use of these arrays is often discouraged because there is no interface through which the allocation can fail (malloc can return NULL, but if a VLA cannot be allocated, the program will segfault or worse, behave erratically).

提交回复
热议问题