i wasnt sure abt the first part of it. the one with multiple initializations ... :P
On Sun, Jul 17, 2011 at 3:09 AM, sagar pareek <sagarpar...@gmail.com> wrote: > Well shubham if you know about the unions very well then why u asked this > question? > > > On Sun, Jul 17, 2011 at 2:27 AM, Shubham Maheshwari < > shubham.veloc...@gmail.com> wrote: > >> :D >> >> >> On Sun, Jul 17, 2011 at 2:24 AM, Kamakshii Aggarwal < >> kamakshi...@gmail.com> wrote: >> >>> @shubham:yes u r right.thanks :) >>> >>> >>> On Sun, Jul 17, 2011 at 2:12 AM, Shubham Maheshwari < >>> shubham.veloc...@gmail.com> wrote: >>> >>>> @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 < >>>> kamakshi...@gmail.com> 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 < >>>>> shubham.veloc...@gmail.com> wrote: >>>>> >>>>>> you mean to say .. the ques is wrong ... or what ...!! >>>>>> >>>>>> >>>>>> On Sun, Jul 17, 2011 at 1:54 AM, sagar pareek >>>>>> <sagarpar...@gmail.com>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 < >>>>>>> shubham.veloc...@gmail.com> 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 algogeeks@googlegroups.com. >>>>>>>> To unsubscribe from this group, send email to >>>>>>>> algogeeks+unsubscr...@googlegroups.com. >>>>>>>> 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 algogeeks@googlegroups.com. >>>>>>> To unsubscribe from this group, send email to >>>>>>> algogeeks+unsubscr...@googlegroups.com. >>>>>>> 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 algogeeks@googlegroups.com. >>>>>> To unsubscribe from this group, send email to >>>>>> algogeeks+unsubscr...@googlegroups.com. >>>>>> For more options, visit this group at >>>>>> http://groups.google.com/group/algogeeks?hl=en. >>>>>> >>>>> >>>>> >>>>> >>>>> -- >>>>> Regards, >>>>> Kamakshi >>>>> kamakshi...@gmail.com >>>>> >>>>> -- >>>>> You received this message because you are subscribed to the Google >>>>> Groups "Algorithm Geeks" group. >>>>> To post to this group, send email to algogeeks@googlegroups.com. >>>>> To unsubscribe from this group, send email to >>>>> algogeeks+unsubscr...@googlegroups.com. >>>>> 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 algogeeks@googlegroups.com. >>>> To unsubscribe from this group, send email to >>>> algogeeks+unsubscr...@googlegroups.com. >>>> For more options, visit this group at >>>> http://groups.google.com/group/algogeeks?hl=en. >>>> >>> >>> >>> >>> -- >>> Regards, >>> Kamakshi >>> kamakshi...@gmail.com >>> >>> -- >>> You received this message because you are subscribed to the Google Groups >>> "Algorithm Geeks" group. >>> To post to this group, send email to algogeeks@googlegroups.com. >>> To unsubscribe from this group, send email to >>> algogeeks+unsubscr...@googlegroups.com. >>> 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 algogeeks@googlegroups.com. >> To unsubscribe from this group, send email to >> algogeeks+unsubscr...@googlegroups.com. >> 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 algogeeks@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com. > 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 algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.