I did this with gcc compiler. No errors but there were two warning.
prog.c: In function 'main':
prog.c:11: warning: excess elements in union initializer
prog.c:11: warning: (near initialization for 'e')
Output: 10 10
Ayesha said:
(Sun, Jun 10, 2012 02:06:44 PM)
Please anybody explain me in detail.
Vcillusion said:
(Wed, Sep 12, 2012 02:30:20 PM)
union emp e = {10, 25};.
As we can see in above statement both of the members are initialized.
This is not possible as single memory slot is available which is property of union which comes with this one drawback too.
So this is not allowed as maximum of member function only 2 bytes is allocated to emp union so how could it use this 2 byte memory to initialize all member function at once.
I hope it makes it clear.
Raja Ghosh said:
(Wed, Jan 23, 2013 07:21:59 PM)
However we can pass as many values as in the union variable.
But union only gets initialized with one value (leftmost in the parenthesis as per comma operator usage) so here it will take 10.
So the programs runs correctly with warning as: excess elements in union initializer.