Question 3 of 146 points

Question 3 · 6 points

Calculate a tagged union’s size

On a typical 64-bit system, what does sizeof(Variant) return? Explain the size and alignment of the enum, union, and enclosing structure, including any padding.

typedef enum { INT_T, DBL_T, STR_T } type_t;

typedef struct {
    type_t tag;
    union {
        int    i;
        double d;
        char  *s;
    } value;
} Variant;

printf("%zu\n", sizeof(Variant));

Your response

Your answer

0 words