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 158 views
158 views asked Jun 20, 2021 by avibootz
1 answer 228 views
1 answer 166 views
166 views asked Jun 20, 2021 by avibootz
1 answer 184 views
1 answer 75 views
...