In an example that's in my C++ book, I've found this piece of code at the end of an example problem, which verified if 3 integers were in an arithmetic progression.
if (b==(a+c)/2.)
I don't think I've seen the dot after 2 ever used in such a way and I don't know what it's purpose is here.
2. is a double literal. It's the same as 2.0.
Integer division is different than floating point division, so in some cases having a double instead of an int makes an important difference.
Although this form is perfectly valid, for readability purposes often 2.0 is preferred. In some (not all) newer languages derived from C++ like C# it is not allowed, i.e. you are forced to write 2.0.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With