0

What is wrong in my calculation?

What is output of this code? union uTemp { double a; int b[10]; char c; } u; int main() { printf("%d\n", sizeof(u)); } Double 1*4=4 Int 10*2 =20 Char 1*1=1 Total--25 But the answer has 40. How??

3rd Jun 2021, 4:11 PM
Soharab Uddin Mondal
Soharab Uddin Mondal - avatar
2 ответов
+ 3
int size is 4 so int 10 * 4 = 40 So union considered max value and max value is 40. That's why it is 40. Note : Size of the union is the the size of its largest field because sufficient number of bytes must be reserved to store the largest sized field
3rd Jun 2021, 4:24 PM
A͢J
A͢J - avatar
4th Jun 2021, 1:30 AM
Soharab Uddin Mondal
Soharab Uddin Mondal - avatar