204. Union

Question.4

A protocol uses different payloads based on message type:

struct Message {
   uint8_t type;
   union {
        struct { int x, y; } gps;
        struct { float volt; } battery;
        struct { char text[10]; } log;
   } payload;
};

printf("%zu", sizeof(Message));

What is the size of payload? (Assume 4-byte int, 4-byte float.)

Need Help? Refer to the Quick Guide below

Select Answer