Saturday, 25 February 2017

GATE EXAM PREPARATION IN "C" - C declaration(GATE CS 2000)

 Consider the following C declaration
struct {
    short s [5]
    union {
         float y;
         long z;
    }u;
} t;


Assume that objects of the type short, float and long occupy 2 bytes, 4 bytes and 8 bytes, respectively. The memory requirement for variable t, ignoring alignment
considerations, is 

(a) 22 bytes
(b) 14 bytes
(c) 18 bytes
(d) 10 bytes
Answer: (c)
Explanation: Short array s[5] will take 10 bytes as size of short is 2 bytes. Since u is a union, memory allocated to u will be max of float y(4 bytes) and long z(8 bytes). So, total size will be 18 bytes (10 + 8).


No comments:

Post a Comment