I have stored the value of Pi in 2 different variables, one as float and the other as double. The code displays the sizes as 4 bytes and 8 bytes for the float and double ones respectively.
The question is when I try to display the size of 3.14, a decimal number (in the 3rd cout statement)(which I suppose is a floating point number) it displays a size of 8 bytes instead of 4 bytes.
What does this mean? Does C++ treats a decimal number as double by default?
sizeof() returns the size of the variable. The output is correct because double variables are of size 8 bytes while floats are 4 bytes. It has nothing to do with the current value of the variable.
Yeah, I knew about the suffixes and typecasting, but what I wanted to confirm is that "by default C++ treats decimal values as double instead of float".
Why shouldn't it be? float with its 32 bits is horribly inaccurate and hardly suitable for generic use.
float is used mainly in 3D programming, as there, size is far more important than precision.