Relationship between structs in C

1

I have the following scenario:

typedef struct Unidade{
    int cod;
} und;

typedef struct Produto{
    int cod;
    char nome[100];
    und unidade;
} prod;

As you can see, I have a unit-type variable inside the product. How do I record this variable and how to access it?

In unidade write like this: u

nidade.cod = 10;

In produto would it look like at the time of writing to this variable unidade ? And how would I read this variable later?

    
asked by anonymous 11.05.2017 / 19:52

1 answer

1

It's basically

produto.unidade.cod = 10;

where produto is the instance variable.

The reading would look like this:

produto.unidade.cod

If the object is created as a pointer there would have to use the -> operator instead of . .

Improvement if the question has more details.

    
11.05.2017 / 20:05