1

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?

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335
NicoCaldo
  • 1,171
  • 13
  • 25
  • 2
    Yes, `ppl_weightList` is an array of 16 structs. You can access it like any other array. For more help you might provide more details where your doubts are. – Gerhardh Jul 01 '22 at 07:27
  • As you said, you have an`ppl_weight ` array size of 16. It is the same as `int x[16]` but the data type is the `ppl_weight ` struct. – Seyed Mohammad Amin Atyabi Jul 01 '22 at 07:29

2 Answers2

3

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];
Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335
1

We can declare structure variables at the time of defining structure as follows

struct packet
{
  int range;
  char head;
}p1, p2, p3;