C Programming - Floating Point Issues - Discussion

1. 

Which of the following is suitable data type for the variable a in the statement given below?
(datatype) a = 23.45;

[A]. float
[B]. double
[C]. long double
[D]. long float

Answer: Option A

Explanation:

No answer description available for this question.

Amanpreet said: (Oct 3, 2010)  
How to do it?

Sundar said: (Oct 3, 2010)  
The 'float' is pretty enough to hold the data 23.45.

We can go for other data-type if the given number is out of the float ranges.

Ranges of different data types: Turbo C (Windows Platform)

float         (32 bits)   3.4 * (10^-38) to 3.4 * (10^+38)
double (64 bits) 1.7 * (10^-308) to 1.7 * (10^+308)
long double (80 bits) 3.4 * (10^-4932) to 1.1 * (10^+4932)

Amit said: (Oct 8, 2010)  
I am not sure but but the answer can be double also so I think its a ambiguity here.

Niranjan Reddy said: (Nov 3, 2010)  
By default any real number will be double, if and only if we mention it as float.

Mahesh said: (Nov 12, 2010)  
i think by default th real number is treated as adouble
so the answer should be double

Gopal said: (Nov 16, 2010)  
I think ans will be double because if it is float then it will be ended "f" by default real number will be double.

Kumar said: (Nov 17, 2010)  
@All

The C compiler will treat this 23.45 number as 'double'.

But the questions is about which datatype is suitable for the given data 23.45.

The float data type is very much suitable to hold 23.45.

Hence 'float' is the answer.

Go through the Sundar's explanation for better understanding.

Have a nice day!

Rajendar said: (Dec 17, 2010)  
Yes float is the answer.

Chandu said: (May 8, 2012)  
Default the real number is treated as adouble.

So the answer should be double.

Tapan said: (Oct 23, 2012)  
The Answer should be double, as by default 23.45 is double and we should keep in mind the precision as well.

We see,

23.45 is never exactly representable in float (binary) representation so there will be loss of precision if we store it in float but lesser if we store it in double.

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.