Hey all

Can anyone suggest me some material (Advanced level) which contains many Multiple choice Q's on outputs or concepts (in C) or even MCQ's on Data structures using C.

Also

O/p

float a=0.7;
if(a>0.7) print hell
else print no

Ans is compiler dependent But y is it So ?

2. floats cannot be perfectly stored in a 32 bit value, there is always some amount of precision that is lost. An easy way to see this in action is to do:
Code:
printf("%.10f\n", a);
On my box, 0.7 is printed as 0.6999999881

3. r u having a 16 bit compiler?

4. 0.7 (decimal) cannot be represented exactly as a binary (base 2) fraction. Floating point formats are a binary representation.

5. Originally Posted by bithub
floats cannot be perfectly stored in a 32 bit value, there is always some amount of precision that is lost. An easy way to see this in action is to do:
Code:
printf("%.10f\n", a);
On my box, 0.7 is printed as 0.6999999881
That is why you shouldn't compare floating point numbers with the C relational operators. You should take rounding errors into account like this:
Code:
#include <math.h>

inline int Greater(float a, float b)
{
return (b-a) <= -TOLERANCE;
}
Or something like that.

6. The right way to program it is
Code:
float a = 0.7f;
if (a > 0.7f) {
/* you will not reach this hell */
} else {
/* this is the place we go */
}
The reason ist that 0.7 is a double value and therefor rounded when assigned to a float. Adding the f after the literal marks it explicitly as float.
Well of corse 0.7f is in reality somewhere between 0.6999.. and 0.70...01... but at least there are no rounding surprises in the example code, as both values are rounded the same way.

When working with float and double you shall always be aware that there is some fraction of uncertainty due to rounding issues. Use integer calculations if you have to be sure which way the rounding goes.

7. Thanx a lot guys
And can anyone guide me to some good MCQ book or online resource.
Q's related to 'Whats the output'