@Kamakshii:
thats probably becuz a union has a common memory location, accessed by all
its members.
so, the value '100' is treated as an int by 'a', as a char array by 'b' and
as a float by 'c'.
I thnk i read this read tis somewhere sometime back. ... so aint completely
sure abt it.

On Sun, Jul 17, 2011 at 2:08 AM, Kamakshii Aggarwal
<[email protected]>wrote:

>
> u can always retrieve that value from the union that has been assigned
> last.therefore u get correct answer only for x.c
>
> in the case of union y
> y.a=100 and so the output
> but am not sure why y.b is printing character equivalent of 100.
>
>
> On Sun, Jul 17, 2011 at 1:58 AM, Shubham Maheshwari <
> [email protected]> wrote:
>
>> you mean to say .. the ques is wrong ... or what ...!!
>>
>>
>> On Sun, Jul 17, 2011 at 1:54 AM, sagar pareek <[email protected]>wrote:
>>
>>> I think you must first read about unions and the differences between
>>> union and structures :)
>>>
>>> On Sun, Jul 17, 2011 at 1:48 AM, Shubham Maheshwari <
>>> [email protected]> wrote:
>>>
>>>> "union" Data Type
>>>> What is the output of the following program? Why?
>>>> #include
>>>> main() {
>>>> typedef union {
>>>> int a;
>>>> char b[10];
>>>> float c;
>>>> }
>>>> Union;
>>>> Union x,y = {100};
>>>> x.a = 50;
>>>> strcpy(x.b,"hello");
>>>> x.c = 21.50;
>>>> printf("Union x : %d %s %f n",x.a,x.b,x.c);
>>>> printf("Union y : %d %s %f n",y.a,y.b,y.c);
>>>> }
>>>>
>>>> --
>>>> Shubham Maheshwari
>>>> ShubZz
>>>> O.o o.O
>>>>
>>>> enJoY ...!!!
>>>>
>>>>  --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Algorithm Geeks" group.
>>>> To post to this group, send email to [email protected].
>>>> To unsubscribe from this group, send email to
>>>> [email protected].
>>>> For more options, visit this group at
>>>> http://groups.google.com/group/algogeeks?hl=en.
>>>>
>>>
>>>
>>>
>>> --
>>> **Regards
>>> SAGAR PAREEK
>>> COMPUTER SCIENCE AND ENGINEERING
>>> NIT ALLAHABAD
>>>
>>>  --
>>> You received this message because you are subscribed to the Google Groups
>>> "Algorithm Geeks" group.
>>> To post to this group, send email to [email protected].
>>> To unsubscribe from this group, send email to
>>> [email protected].
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>
>>
>> --
>> Shubham Maheshwari
>> ShubZz
>> O.o o.O
>>
>> enJoY ...!!!
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> Regards,
> Kamakshi
> [email protected]
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
Shubham Maheshwari
ShubZz
O.o o.O

enJoY ...!!!

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to