wat's the o/p of pgm??

Go down

wat's the o/p of pgm??

Post by Naveen on Mon Mar 08, 2010 4:29 pm

float f=5.5;
double d=5.5;
if(f==d)
cout<<"Equal";
else
cout<<"Not equal";

i get not equal as o/p..
y is it so?

Naveen

Posts : 15
Points : 21
Join date : 2010-03-05
Age : 29

View user profile

Back to top Go down

Re: wat's the o/p of pgm??

Post by Christopher on Mon Mar 08, 2010 4:40 pm

r u asking in java or c++??? In c++, it is equal. But java is strongly typed language, so float and double are different. I think thaty u r getting not equal. not sure. ll give a try.
avatar
Christopher
Admin

Posts : 240
Points : 429
Join date : 2010-02-26
Age : 30

View user profile http://unixcpp.forumotion.com

Back to top Go down

Re: wat's the o/p of pgm??

Post by Naveen on Mon Mar 08, 2010 4:41 pm

Hey even in c++ i do get the sam o/p...
u jus check it out...

Naveen

Posts : 15
Points : 21
Join date : 2010-03-05
Age : 29

View user profile

Back to top Go down

Re: wat's the o/p of pgm??

Post by Christopher on Mon Mar 08, 2010 4:58 pm

i tried it. it s working fine. anyways it depends on the compiler we use. which compiler r u using??
avatar
Christopher
Admin

Posts : 240
Points : 429
Join date : 2010-02-26
Age : 30

View user profile http://unixcpp.forumotion.com

Back to top Go down

Re: wat's the o/p of pgm??

Post by Naveen on Mon Mar 08, 2010 5:03 pm

Dev... wat compiler do u use?

Naveen

Posts : 15
Points : 21
Join date : 2010-03-05
Age : 29

View user profile

Back to top Go down

Re: wat's the o/p of pgm??

Post by Christopher on Mon Mar 08, 2010 5:19 pm

check ur pgm. the following stmt ll throw u error when u try to compile it.

Code:
float f=5.5

by default decimal values are double in java. so if u want to initialize a float variable, u have to type cast it.

Code:
float f=5.5f;
or
float f=5.5F;
or
float f=(float)5.5;
avatar
Christopher
Admin

Posts : 240
Points : 429
Join date : 2010-02-26
Age : 30

View user profile http://unixcpp.forumotion.com

Back to top Go down

Re: wat's the o/p of pgm??

Post by Naveen on Mon Mar 08, 2010 5:33 pm

Yeaaa got it...

Naveen

Posts : 15
Points : 21
Join date : 2010-03-05
Age : 29

View user profile

Back to top Go down

Re: wat's the o/p of pgm??

Post by Sponsored content


Sponsored content


Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum