Union u{ union u { int i; int j; }a[10]; int b[10];}u;main(){ printf("n%d", sizeof(u)); printf(" %d", sizeof(u.a));// printf("%d", sizeof(u.a[4].i));}

A) None of the Above
B) 1, 100, 1
C) 40, 4, 4
D) 4, 4, 4
Explanation: 20, 200, error for 3rd printf

Showing Answers 1 - 9 of 9 Answers

Amit

  • Dec 14th, 2005
 

20,20,2

  Was this answer useful?  Yes

wlochaty

  • Jan 19th, 2006
 

it depends on implementation.sizeof(int)= 4 rather than 2 so this might be:40 40 4 which also is A)None of Above.

  Was this answer useful?  Yes

abhimanipal

  • Jan 24th, 2010
 

If I uncomment the third printf I get the following error

pollux {~} > gcc test.c -o test
test.c: In function `main':
test.c:21: error: union has no member named `i'
pollux {~} >

This is on linux machine with gcc compiler. Can anyone explain the reason for this ?

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions