wiz-icon
MyQuestionIcon
MyQuestionIcon
1
You visited us 1 times! Enjoying our articles? Unlock Full Access!
Question

Consider the following C declaration
struct {
Short S[5]
union {
floaty;
long z;
}u;
}t;
Assume that objects of the type short, float and long occupy 2 bytes, 4 bytes, 8 bytes, respectively. The memory requirement for variable t, ignoring alignment considerations, is

A
22 bytes
No worries! We‘ve got your back. Try BYJU‘S free classes today!
B
14 bytes
No worries! We‘ve got your back. Try BYJU‘S free classes today!
C
18 bytes
Right on! Give the BNAT exam to get a 100% scholarship for BYJUS courses
D
10 bytes
No worries! We‘ve got your back. Try BYJU‘S free classes today!
Open in App
Solution

The correct option is C 18 bytes

struct{
ShortS[5]
union{
floaty;
longz;
}u;
}t;
Assume that objects of the type short, float and long occupy 2 bytes, 4 bytes, 8 bytes, respectively. The memory requirement for variable t, ignoring alignment considerations, is 18.

Short array s[5] will take 10 bytes as size of short is 2 bytes.

When we declare a union, memory allocated for the union is equal to memory needed for the largest member of it, and all members share this same memory space. 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).



flag
Suggest Corrections
thumbs-up
0
Join BYJU'S Learning Program
similar_icon
Related Videos
thumbnail
lock
Multiplication of Integers_tackle
MATHEMATICS
Watch in App
Join BYJU'S Learning Program
CrossIcon