• C

Doubt in Typecast

#include <stdio.h>
main()
 {
int a;
 double b=xxxxxxx.xxxxx;//Some value
 a=(int)b;
 printf("%d",a);
}

agowthamAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ozoCommented:
What doubt are you having?
0
AggarwalCommented:

 however its not clear from ur question whats ur doubt ..

 i guess it will be regarding value of a .

 keep in mind downcasting always truncates the data ..*no rounding* ..

 e.g.

 b = X.Y .. where X,Y have some values ..

 after a = (int)b . .. value of a will be X if its within max range of int for a particular OS .. otherwise it will get rotated ..

what i mean by rotation .. suppose any type can have ..

-Z,-Z+1,-Z+2 ...0...1,2,3,...Z-1,Z ...possible values

now a is X ... let X is greater than Z by some value say d

then value of a will be '-Z+d-1'  ..

hope that helps ..

aggarwal
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ozoCommented:
Actually, when a floating type is converted to an integral type, if the value of the integral part cannot be represented by the integral type the behavior is undefined.
0
Lab_RatCommented:
Compiler dependent then? Who needs platform dependence!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.