Here is the modified code. Maybe we can find something new.
Code: #include<stdio.h> int main() { union { struct { int x; float t; }; double u; } a; a.x=0; scanf("%f",&a.t); printf("%f\n",a.t); printf("%f\n",a.u); a.x=90; printf("%d\n",a.x); printf("%f\n",a.x); printf("%f\n",a.t); printf("%f\n",a.u); a.x=1; printf("%d\n",a.x); printf("%f\n",a.x); printf("%f\n",a.t); printf("%f\n",a.u); a.x=30; printf("%d\n",a.x); printf("%f\n",a.x); printf("%f\n",a.t); printf("%f\n",a.u); a.x=9; printf("%d\n",a.x); printf("%f\n",a.x); printf("%f\n",a.t); printf("%f\n",a.u); return 0; } Input: 3 Output: 3.000000 32.000000 90 32.000000 3.000000 32.000000 1 32.000000 3.000000 32.000000 30 32.000000 3.000000 32.000000 9 32.000000 3.000000 32.000000 Input: 32 Output: 32 32.000000 8589934592.000000 90 8589934592.000172 32.000000 8589934592.000172 1 8589934592.000002 32.000000 8589934592.000002 30 8589934592.000057 32.000000 8589934592.000057 9 8589934592.000017 32.000000 8589934592.000017 On 2010-10-11 2:06, Asquare wrote:
As far as I have understood.. Its basically that once you give the input to t as float, that value is displayed for all the printf functions except one because of the %f modifier.. the %f modifier cannot accept x (int) as a successful argument so it takes the latest float value.. but in case of x=30; printf("%d\n",x); this printf has %d as modifier so the output is 30. say t entered is 43.5 so OUTPUT: (as per gcc compiler) 43.5 43.5 43.5 30 43.5 43.5 correct me if im wrong..
-- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@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.