Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Doubt in Typecast

Posted on 1999-06-25
Medium Priority
Last Modified: 2012-05-04
#include <stdio.h>
int a;
 double b=xxxxxxx.xxxxx;//Some value

Question by:agowtham
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 84

Expert Comment

ID: 1262966
What doubt are you having?

Accepted Solution

Aggarwal earned 100 total points
ID: 1262967

 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* ..


 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 ..

LVL 84

Expert Comment

ID: 1262968
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.

Expert Comment

ID: 1262969
Compiler dependent then? Who needs platform dependence!

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode ( They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question