sizeof float (3.0) vs (3.0f)

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.

Leave a Comment