Home › Forums › C Programming › help plz…………..
- This topic has 1 reply, 2 voices, and was last updated 11 years ago by
LenoraRamsey.
Viewing 1 reply thread
- AuthorPosts
- February 28, 2010 at 3:59 pm #2242
DeenaDeBernales
Participant#include
void main()
{
long double a =0;
if(a>float(0))
printf(“hi”);
else
printf(“hello”);
)why it outputs hello ………….plz explain ………………
- March 2, 2010 at 5:26 am #3640
LenoraRamsey
ParticipantActually, In C float and double has only two differences. one is size. and another one is storage in memory.
float has only single precision. But double has double precision.So, In your code you are trying to differentiate this. But it gives output as hello because it is equal.
double 0 is equal to float 0.If you want differentiate float and double try this code.
1234567891011<br />#include<stdio.h><br />main()<br />{<br />long double a =0.0;<br />if(a>=(float)0.0)<br />printf("hi");<br />else<br />printf("hello");<br />}<br />It will prints hi.
1234567891011<br />#include<stdio.h><br />main()<br />{<br />long double a =0.1;<br />if(a>=(float)0.1)<br />printf("hi");<br />else<br />printf("hello");<br />}<br />It will prints hello.
I think now you can get the difference.
- AuthorPosts
Viewing 1 reply thread
- The forum ‘C Programming’ is closed to new topics and replies.