Can you define the size of an array at runtime in C

后端 未结 10 1281
走了就别回头了
走了就别回头了 2021-01-02 18:35

New to C, thanks a lot for help.

Is it possible to define an array in C without either specifying its size or initializing it.

For example, can I prompt a u

10条回答
  •  悲哀的现实
    2021-01-02 19:00

    Arrays, by definition, are fixed-size memory structures. You want a vector. Since Standard C doesn't define vectors, you could try looking for a library, or hand-rolling your own.

    You need to do dynamic allocation: You want a pointer to a memory address of yet-unkown size. Read up on malloc and realloc.

提交回复
热议问题