+ 3

Why write f behind number?

Hello I dont und erstand the diffrence between: float w= 3.56f and const float w = 3.56

3rd Feb 2018, 5:02 PM
Rambo Schweiz
Rambo Schweiz - avatar
3 Respostas
+ 6
@Rambo Nope Focus only on KrOW's second advice That is 3.58 is double precision while 3.5f is float precision if you paste 3.58 like this float f=3.58; 3.58 must be converted to float while itself double but if you paste 3.58f like this float f=3.58f; 3.58f won't be converted later if compiler optimize about this. 3.58f and 3.58 won't have any difference at all however you should leave f to tell your number is float
3rd Feb 2018, 5:46 PM
Yanothai Chaitawat
Yanothai Chaitawat - avatar
+ 4
First: const indicate "the variable cannot change value": float f= 3.5f; const float cf = 4.5f; cf = 10.3f; // error: dont compile. you cant reassign a const var Second: 3.58 is a bit different from 3.58f. in the first case the value is a double (not float) value while in second case it is a float: float d = 3.58; // here will be a double to float conversion float f = 3.58f; // here will be no conversion
3rd Feb 2018, 5:20 PM
KrOW
KrOW - avatar
+ 2
float w = 3.56 \\ normal float not a Constant float w = 3.56f \\constant float const float w = 3.56 \\ also Constant float, just a different way to write Correct like this??? Same with long long (ll behindert number)?
3rd Feb 2018, 5:05 PM
Rambo Schweiz
Rambo Schweiz - avatar