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…

358615Medium 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;
  • A24 bytes
  • B10 bytes
  • C18 bytes
  • D22 bytes
Correct answer: C

Explanation

short a[5] takes 5 × 2 = 10 bytes. A union takes the size of its largest member, which is long = 8 bytes. Total = 10 + 8 = 18 bytes.

Discussion 0

Nobody has replied yet. Start the discussion!