Type Conversion Suffixes

I have a problem writing literals on the compiler. When I declare variables as:

int Variable = 5;

this not have any problems, because my book said that literals are by default recognized as integers. But when I declare this:

long Variable = 500000;

the compiler send me a warning telling me that its happening a type conversion of int to long and could happen a loss of data. I don't understand this because I had declared it as long in the first place. I read a lot more to avoid this warning and it says that I have to add a suffix like this:

long Variable = 500000L;

this is done to also transform the rvalue (Right value) to long in order to avoid misunderstanding of an int number. I have problems when I have to do this also:

float Variable = 2.5;

the number 2.5 is a float number so I don't understand why it recognize it as double. The worst problem is when it said that could happen a truncating variable. This is another annoying declaration:

const float Variable = 2.658;

It also throw me the warning but on this case I can't manipulate it as static_cast to fix it.

I would like that someone could explain a little more about this suffixes because out there are less information about this. My book don't take this so seriously and don't include more information about this. The type conversion its a serious problem and make my outputs erroneous.

My second question is that, what are the others suffixes used for short, unsigned short, int, unsigned int, long, unsigned long, float, double, long double , bool and char?
f or F =>float
l or L =>long double or long (depending on context)
u or U=>unsigned int
ul =>unsigned long (in any order and any case, ul,Ul,lU,etc.)

by default integer literals are of type int,and floating point literals of type double,so you shold type suffix to make compiler understand what you mean
Topic archived. No new replies allowed.