Hi,
What is the difference between sizeof(3.0) and sizeof(3.0f)
I was expecting both of them to give the same result (sizeof float)..but its different.
In 32 bit machine,gcc compiler, sizeof(3.0f) =>4 sizeof(3.0) => 8
Why so?
Hi,
What is the difference between sizeof(3.0) and sizeof(3.0f)
I was expecting both of them to give the same result (sizeof float)..but its different.
In 32 bit machine,gcc compiler, sizeof(3.0f) =>4 sizeof(3.0) => 8
Why so?
Because 3.0 is a double. See C syntax Floating point types.
Floating-point constants may be written in decimal notation, e.g. 1.23. Scientific notation may be used by adding e or E followed by a decimal exponent, e.g. 1.23e2 (which has the value 123). Either a decimal point or an exponent is required (otherwise, the number is an integer constant). C99 introduced hexadecimal floating-point constants, which follow similar rules except that they must be prefixed by 0x and use p to specify a hexadecimal exponent. Both decimal and hexadecimal floating-point constants may be suffixed by f or F to indicate a constant of type float, by l or L to indicate type long double, or left unsuffixed for a double constant.
3.0 is a double
, not a float
.
doubles
are twice as wide as float
s.
EDIT: 3.0d is only in C#