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

x
?
Solved

Doubt in Typecast

Posted on 1999-06-25
4
Medium Priority
?
188 Views
Last Modified: 2012-05-04
#include <stdio.h>
main()
 {
int a;
 double b=xxxxxxx.xxxxx;//Some value
 a=(int)b;
 printf("%d",a);
}

0
Comment
Question by:agowtham
[X]
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
4 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 1262966
What doubt are you having?
0
 
LVL 1

Accepted Solution

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

 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
 
LVL 84

Expert Comment

by:ozo
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.
0
 
LVL 1

Expert Comment

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

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 (http://en.wikipedia.org/wiki/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