OFF-TOPIC : Confusion about basic C program behaviour

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

  I know this is not the correct place to post this
question, but I feel it would be pretty easy for the
kernel gurus to explain this.  

TEST CODE
==========

#include <stdio.h>

main()
{
   float a1=1.0;
   float a2=2.0;

   printf(" \n");
   printf(" Size of Float > %d \n", sizeof(float) );
   printf(" Size of Int   > %d \n", sizeof(int) );
   printf(" \n");

   printf(" CASE 1 : f-f > %f - %f \n\n", a1, a2);
   printf(" CASE 2 : f-d > %f - %d \n\n", a1, a2);
   printf(" CASE 3 : d-f > %d - %f \n\n", a1, a2);
   printf(" CASE 4 : d-d > %d - %d \n\n", a1, a2);
}

OUTPUT :

 Size of Float > 4
 Size of Int   > 4

 CASE 1 : f-f > 1.000000 - 2.000000

 CASE 2 : f-d > 1.000000 - 0

 CASE 3 : d-f > 0 - 0.000000

 CASE 4 : d-d > 0 - 1072693248

==================================

The CASE1 & CASE2 & CASE4 outputs are expected.

   Any explanation for CASE3 behaviour. 
   I presume it should behave similar to CASE2 and
print 0 - 2.000000 .

   Could somebody please pin-point what is 
lacking in my presumtion .

Thanks !



		
__________________________________ 
Do you Yahoo!? 
Yahoo! Mail - Easier than ever with enhanced search. Learn more. 
http://info.mail.yahoo.com/mail_250

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux