How to convert double to bool in C

2 Answers

0 votes
#include <stdio.h> 
#include <stdbool.h>

int main(void) 
{ 
    double d = 121.871;
	bool b = d != 0.0;
	
    fputs(b ? "true" : "false", stdout);
     
    return 0; 
} 
   
   
   
/*
run:
   
true
 
*/

 



answered Aug 10, 2019 by avibootz
0 votes
#include <stdio.h> 
#include <stdbool.h>

int main(void) 
{ 
    double d = 0.0;
	bool b = d != 0.0;
	
    fputs(b ? "true" : "false", stdout);
     
    return 0; 
} 
   
   
   
/*
run:
   
false
 
*/

 



answered Aug 10, 2019 by avibootz

Related questions

1 answer 297 views
297 views asked Aug 11, 2019 by avibootz
1 answer 327 views
327 views asked Aug 11, 2019 by avibootz
2 answers 393 views
393 views asked Aug 11, 2019 by avibootz
2 answers 401 views
401 views asked Aug 10, 2019 by avibootz
1 answer 261 views
261 views asked Aug 10, 2019 by avibootz
2 answers 358 views
358 views asked Aug 10, 2019 by avibootz
1 answer 555 views
555 views asked Aug 7, 2019 by avibootz
...