Search code examples
arrayscstructdeclaration

What does the variable array name at the end of the structure's definition means?


I've already read this, this and this but it seems they're not exactly my situtation.

I have a code like this

struct ppl_weight {
    uint16_t weight;
    uint8_t weightHour;

} ppl_weightList[16];

but I can't understand the array at the end of the struct. What does it mean? Have I an array of 16 struct? How does I manage this data type?


Solution

  • It is a declaration of an array with 16 elements of the type struct ppl_weight. You could split this declaration

    struct ppl_weight {
        uint16_t weight;
        uint8_t weightHour;
    
    } ppl_weightList[16];
    

    the following way

    struct ppl_weight {
        uint16_t weight;
        uint8_t weightHour;
    
    };
    
    struct ppl_weight ppl_weightList[16];