C Programming - Floating Point Issues - Discussion
Discussion Forum : Floating Point Issues - Point Out Correct Statements (Q.No. 1)
1.
Which of the following is suitable data type for the variable a in the statement given below?
(datatype) a = 23.45;
(datatype) a = 23.45;
Discussion:
10 comments Page 1 of 1.
Tapan said:
1 decade ago
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.
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.
Chandu said:
1 decade ago
Default the real number is treated as adouble.
So the answer should be double.
So the answer should be double.
Rajendar said:
2 decades ago
Yes float is the answer.
Kumar said:
2 decades ago
@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!
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!
Gopal said:
2 decades ago
I think ans will be double because if it is float then it will be ended "f" by default real number will be double.
(1)
Mahesh said:
2 decades ago
i think by default th real number is treated as adouble
so the answer should be double
so the answer should be double
Niranjan reddy said:
2 decades ago
By default any real number will be double, if and only if we mention it as float.
Amit said:
2 decades ago
I am not sure but but the answer can be double also so I think its a ambiguity here.
Sundar said:
2 decades ago
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)
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)
Amanpreet said:
2 decades ago
How to do it?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers