How to get the length of a dynamically created array of structs in C?

前端 未结 4 849
轻奢々
轻奢々 2021-01-02 12:16

I am currently trying to get the length of a dynamically generated array. It is an array of structs:

typedef struct _my_data_ 
{
  unsigned int id;
  double          


        
4条回答
  •  生来不讨喜
    2021-01-02 12:46

    If you need to know the size of a dynamically-allocated array, you have to keep track of it yourself.

    The sizeof(arr) / sizeof(arr[0]) technique only works for arrays whose size is known at compile time, and for C99's variable-length arrays.

提交回复
热议问题