Array of C structs

后端 未结 4 1632
面向向阳花
面向向阳花 2021-01-16 10:54

If I create a struct in C and want to add them to an array that is not set to a fixed size, how is the array created?

Can one create a tempStruct which is used on ev

4条回答
  •  日久生厌
    2021-01-16 11:35

    If you are using the older C89 standard compiler, you cannot use variable length arrays. If you use C99 then you can create variable length array. For clarification: variable-lenght doesnt mean that the array lenght can change during execution. It just means that you can set it during execution instead of fixing a value during compile time.

    For eg:

    CreateArray(const int numberOfElements)
    {
           struct MyStruct arrayOfStructs[numberOfElements];
    }
    

    This is valid in C99 but not in C89. Check your compiler documentaion.

提交回复
热议问题