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 299 views
299 views asked Aug 11, 2019 by avibootz
1 answer 328 views
328 views asked Aug 11, 2019 by avibootz
2 answers 397 views
397 views asked Aug 11, 2019 by avibootz
2 answers 403 views
403 views asked Aug 10, 2019 by avibootz
1 answer 262 views
262 views asked Aug 10, 2019 by avibootz
2 answers 360 views
360 views asked Aug 10, 2019 by avibootz
1 answer 559 views
559 views asked Aug 7, 2019 by avibootz
...