Question discussion

Consider the following C declaration. Assume that objects of data type short, float and long occupy 2 bytes, 4 bytes and 8 bytes respective…

360021Medium DSSSB TGT Computer Science 0 replies 0 views
0

Consider the following C declaration. Assume that objects of data type short, float and long occupy 2 bytes, 4 bytes and 8 bytes respectively. What is memory requirement for variable t?

struct {
    short a[5];
    union {
        float v;
        long z;
    } u;
} t;
  • A22 bytes
  • B18 bytes
  • C24 bytes
  • D10 bytes
Correct answer: B

Explanation

The array a takes 5 × 2 = 10 bytes. The union takes the size of its largest member = 8 bytes (long). Total = 10 + 8 = 18 bytes.

Discussion 0

Nobody has replied yet. Start the discussion!