665 views

1 Answer

2 votes
2 votes

Output:Print B

 if(a==6.7)


Here float is compared with double condition become false.

float and double are two different data types in C for storing real numbers. double occupies twice the memory occupied by float.

We know that numbers or any data in computers are stored in binary and not in decimals. So before storing 6.7 to variable 'a', computer converts it to its binary equivalent.

While storing this value in float variable, only some bits are stored, depending on the size of float variable, and rest are discarded. So the number stored is bit smaller than 6.7 itself. And hence the comparison fails.

To get rid of problem make

(i) make variable  a  double

or

(ii) type cast a to float

Related questions

1 votes
1 votes
0 answers
1
Balaji Jegan asked Oct 23, 2018
197 views
1 votes
1 votes
0 answers
2
0 votes
0 votes
0 answers
3
Gatetarget_100 asked Aug 3, 2018
532 views
int main() { int a[10]; printf("%d",*a+1-*a+3); return 0; }Answer is given as 4 but i think it should be 8, if int is of 4 byte. Correct me if i am wrong
1 votes
1 votes
0 answers
4
Shijith M asked Aug 1, 2018
785 views
int main(){ static int i=5; if( i){ main(); printf("%d ",i); }} This program answer is 0 0 0 0 .how is this? Please explain to me.