How can I create a dynamically sized array of structs?

后端 未结 10 1203
春和景丽
春和景丽 2020-11-27 11:46

I know how to create an array of structs but with a predefined size. However is there a way to create a dynamic array of structs such that the array could get bigger?

<
10条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-27 12:26

    In C++, use a vector. It's like an array but you can easily add and remove elements and it will take care of allocating and deallocating memory for you.

    I know the title of the question says C, but you tagged your question with C and C++...

提交回复
热议问题