698 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

229
views
0 answers
1 votes
Balaji Jegan asked Oct 23, 2018
229 views
620
views
0 answers
1 votes
hitendra singh asked Sep 4, 2018
620 views
what will be the output of the code please elaborate the scopes ?#include<stdio.h>int a=10,b=20;C(){ a=23; printf("%d %d\n",a,b); D(); a=6,b=7; }D(){ b...
561
views
0 answers
0 votes
Gatetarget_100 asked Aug 3, 2018
561 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
817
views
0 answers
1 votes
Shijith M asked Aug 1, 2018
817 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.