[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 191
  • Last Modified:

Doubt in Typecast

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

0
agowtham
Asked:
agowtham
  • 2
1 Solution
 
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
 
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

Featured Post

Easily manage email signatures in Office 365

Managing email signatures in Office 365 can be a challenging task if you don't have the right tool. CodeTwo Email Signatures for Office 365 will help you implement a unified email signature look, no matter what email client is used by users. Test it for free!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now