Consider the following C declaration
struct (
short s[5];
union {
float y;
long z;
}u;
}t;
Assume that the 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 consideration, is
(A)
22 bytes
(B)
18 bytes
(C)
14 bytes
(D)
10 bytes
Answer: (B)
Explanation:
Here structure creates the minimum of array and union, but union only creates the minimum for only ‘long z’ which is max.
So minimum required =18.
Quiz of this Question
Please comment below if you find anything wrong in the above post
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
05 Apr, 2018
Like Article
Save Article