Struct and matrix, how to relate?

1

I'm making a code for a college job and a question has arisen about how to assign values to an array of type struct .

 struct posicao
{
int x;
int y;
};
struct posicao inimigo_val[5][15] = {
{{0,-1},{0,-1},{0,-1},{0,-1},{0,-1},{0,-1},{0,-1},{0,-1},{0,-1},{0,-1},{0,-1},{0,-1},{0,-1},{0,-1},{0,-1}},
{{0,-1},{0,-1},{0,-1},{0,-1},{0,-1},{0,-1},{0,-1},{0,-1},{0,-1},{0,-1},{0,-1},{0,-1},{0,-1},{0,-1},{0,-1}},
{{0,-1},{0,-1},{0,-1},{0,-1},{0,-1},{0,-1},{0,-1},{0,-1},{0,-1},{0,-1},{0,-1},{0,-1},{0,-1},{0,-1},{0,-1}},
{{0,-1},{0,-1},{0,-1},{0,-1},{0,-1},{0,-1},{0,-1},{0,-1},{0,-1},{0,-1},{0,-1},{0,-1},{0,-1},{0,-1},{0,-1}},
{{0,-1},{0,-1},{0,-1},{0,-1},{0,-1},{0,-1},{0,-1},{0,-1},{0,-1},{0,-1},{0,-1},{0,-1},{0,-1},{0,-1},{0,-1}},
{{0,-1},{0,-1},{0,-1},{0,-1},{0,-1},{0,-1},{0,-1},{0,-1},{0,-1},{0,-1},{0,-1},{0,-1},{0,-1},{0,-1},{0,-1}}
};

I thought about doing the assignment this way, would it be correct? Is there a problem in using struct with array? Is there a more practical way of assigning values? Remembering that there would be different values on each member, this was just an example.

    
asked by anonymous 10.07.2018 / 19:13

1 answer

1

Yes, that's correct.

No problem in using this, it's actually quite common.

There are several other ways to declare, but this one looks good. Some would prefer to be explicit using the names of the members of the structure, but it is not fundamental. I like readability (questionable because it gets longer and may even hurt, it all depends on context).

    
10.07.2018 / 19:21