essue with int

closed account (28poGNh0)
When we initialise a variable int with floting-point value like this int a = 2.5;

why int can only hold 2 rather than puting some at lest warnings
closed account (3qX21hU5)
The integer a does hold a 2. When you assign a floating point value to a integer there is a implicit conversion that happens. And the conversion for a floating point number to a integer is that it just truncates off everything after the decimal.

I can't comment on whatever warnings you are getting without knowing how it is being used and what compiler you are using though.

EDIT: Sorry just reread your post and not sure if you are asking why it doesn't give you warnings that it is doing a implicit conversion from 2.5 to 2 or if it is giving you warning.

Either way I would recommend reading up on implicit conversion since it is basically a must know in programming. You should know what will happen when a conversion between 2 types take place and when the compiler will implicitly do things for you (When you want it to and when you don't want it to).
Last edited on
closed account (28poGNh0)
No I dont get warnings I said maybe is right for compiler to put ones because we dont do some type casting here,or whatever

I am used to this notion but I am looking for deep infos/causes that makes this conversion

also I know this is a conversion but I did not not that it is implicit converstion
so what's an implicit conversion and is there an explicit conversion too

thanks for the reply
Topic archived. No new replies allowed.