can we give size of static array a variable

前端 未结 6 483
余生分开走
余生分开走 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:21

    Some compilers aren't fully C++ standard compliant. What you pointed out is possible in MinGW (iirc), but it's not possible in most other compilers (like Visual C++).

    What actually happens behind the scenes is, the compiler changes your code to use dynamically allocated arrays.

    I would advice against using this kind of non-standard conveniences.

提交回复
热议问题