[algogeeks] urgent C o/p

2011-09-05 Thread Aman Kumar


#includestdio.h
int main()
{
 float a=3.2;
 printf(%d\n\n,a);//line 1
 printf(%d,*(int *)a); //line 2

}


o/p(gcc comppiler) = -1610612736

   1078774989

i am not getting why and how these /p  r coming .

what is difference between line 1   and line 2?

reply asap

-- 
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.



Re: [algogeeks] urgent C o/p

2011-09-05 Thread SANDEEP CHUGH
u r printing a floating point number using %d format specifier.
dnt assume that while printing a float using %d , the compiler will chop the
digits after decimal places.. its not so.. the result will be undefined..

On Mon, Sep 5, 2011 at 1:36 PM, Aman Kumar amanas...@gmail.com wrote:



 #includestdio.h
 int main()
 {
  float a=3.2;
  printf(%d\n\n,a);//line 1
  printf(%d,*(int *)a); //line 2

 }


 o/p(gcc comppiler) = -1610612736

   1078774989

 i am not getting why and how these /p  r coming .

 what is difference between line 1   and line 2?

 reply asap

 --
 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.



-- 
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.



Re: [algogeeks] urgent C o/p

2011-09-05 Thread Shachindra A C
got to do with the internal representation of various types. i think. For
eg, float is composed of a mantissa, exponent etc. So if u try to print a
floating point as an int, you'll get unpredictable outputs.

On Mon, Sep 5, 2011 at 1:36 PM, Aman Kumar amanas...@gmail.com wrote:



 #includestdio.h
 int main()
 {
  float a=3.2;
  printf(%d\n\n,a);//line 1
  printf(%d,*(int *)a); //line 2

 }


 o/p(gcc comppiler) = -1610612736

   1078774989

 i am not getting why and how these /p  r coming .

 what is difference between line 1   and line 2?

 reply asap

 --
 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,
Shachindra A C

-- 
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.



Re: [algogeeks] urgent C o/p

2011-09-05 Thread sukran dhawan
result is undefined.floating points are represented using IEEE ormat which
is not same as ints.so it will truncate fractional part and print result
.result is nt defined

On Mon, Sep 5, 2011 at 1:41 PM, SANDEEP CHUGH sandeep.aa...@gmail.comwrote:

 u r printing a floating point number using %d format specifier.
 dnt assume that while printing a float using %d , the compiler will chop
 the digits after decimal places.. its not so.. the result will be
 undefined..


 On Mon, Seot definep 5, 2011 at 1:36 PM, Aman Kumar 
 amanas...@gmail.comwrote:



 #includestdio.h
 int main()
 {
  float a=3.2;
  printf(%d\n\n,a);//line 1
  printf(%d,*(int *)a); //line 2

 }


 o/p(gcc comppiler) = -1610612736

   1078774989

 i am not getting why and how these /p  r coming .

 what is difference between line 1   and line 2?

 reply asap

 --
 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.


  --
 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.


-- 
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.