tags:

views:

755

answers:

4

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?

+16  A: 

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.

eed3si9n
and 3.0f is a float.
stonemetal
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.=> its too fast to get an answer here :)
kumar
+7  A: 
  • 3.0f is float (4 bytes)
  • 3.0 is double (8 bytes)

more info

Aziz
+4  A: 

3.0 is a double, not a float.

doubles are twice as wide as floats.

EDIT: 3.0d is only in C#

SLaks
There is no 'd' floating point suffix ('l' and 'L' give long double, 'f' and 'F' give float and absence of a suffix gives a double)
AProgrammer
Fixed; thanks.
SLaks
A: 

why 3.0 is double?

manuja