Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sizeof float (3.0) vs (3.0f)

Tags:

c

sizeof

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?

like image 821
kumar Avatar asked Aug 31 '09 00:08

kumar


1 Answers

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.

like image 70
Eugene Yokota Avatar answered Oct 07 '22 14:10

Eugene Yokota