C Programming - Floating Point Issues - Discussion

Discussion Forum : Floating Point Issues - Find Output of Program (Q.No. 5)
5.
What will be the output of the program?
#include<stdio.h>
#include<math.h>
int main()
{
    printf("%d, %d, %d\n", sizeof(3.14f), sizeof(3.14), sizeof(3.14l));
    return 0;
}
4, 4, 4
4, 8, 8
4, 8, 10
4, 8, 12
Answer: Option
Explanation:

sizeof(3.14f) here '3.14f' specifies the float data type. Hence size of float is 4 bytes.

sizeof(3.14) here '3.14' specifies the double data type. Hence size of float is 8 bytes.

sizeof(3.14l) here '3.14l' specifies the long double data type. Hence size of float is 10 bytes.

Note: If you run the above program in Linux platform (GCC Compiler) it will give 4, 8, 12 as output. If you run in Windows platform (TurboC Compiler) it will give 4, 8, 10 as output. Because, C is a machine dependent language.

Discussion:
12 comments Page 1 of 2.

Chaitanya said:   1 decade ago
Its because(3.14l) is double(8 bytes) only,wheres as (3.14L) is long double...its 10 bytes..

So it should be 3.14L for answer 4 8 10,
or else
answer must be 4 8 8

Vijay said:   8 years ago
If we given as 3.14, generally C allocates memory of double (8 bytes), but whenever we specify like 3.14f then it allocates float (4 bytes) memory.

Minal Sharma said:   4 years ago
Size of 3.141 represents long double and size of long double is 16 so, the answer would be 4, 8, 16 which is not in the option.

Jesal said:   1 decade ago
Answer is 4 8 8. Both double & long double size is same. Its given in internet ( data type range)

Tamil selvi said:   9 years ago
My question is same to @Rashmi. Whether identify it is a float or double or long double?

Praveen said:   7 years ago
It shows 4, 8, 12 in the given C compiler, then how you gave the answer as 4, 8, 10?

Amitabh said:   1 decade ago
In gcc it gives 4, 8, 12 for float, double and long double respectively.

Rashmi h k said:   1 decade ago
How can we findout weather it is float or double or long double?

Kamalesh said:   4 years ago
@All.

L or l both are same it has a type long double.

Ranjani said:   1 decade ago
why should we consider 3.14 as double?


Post your comments here:

Your comments will be displayed after verification.