How to convert double to char in C

2 Answers

0 votes
#include <stdio.h> 

int main(void) 
{ 
	double d = 3.14;
	char ch = (char)d;
	
	printf("%d\n", ch);
	
    return 0; 
} 
  
  
  
/*
run:
  
3
 
*/

 



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

int main(void) 
{ 
	double d = 255.982;
	char ch = (char)d;
	
	printf("%d\n", ch);
	
    return 0; 
} 
  
  
  
/*
run:
  
-1
 
*/

 



answered Aug 7, 2019 by avibootz

Related questions

1 answer 153 views
153 views asked Jun 20, 2021 by avibootz
1 answer 224 views
1 answer 162 views
162 views asked Jun 20, 2021 by avibootz
1 answer 178 views
1 answer 73 views
...