i want convert int to char
casting
Collapse
X
-
Tags: None
-
Write a program that reads in three floating-point numbers and sorts them.
For example
4
9
2.5
Use only conditional statement
2.5
4
9
this example want convert int to float or notComment
-
Be careful here.
You cannot convert an int to a char. An int can be 32 or even 64 bits while a char is typically 8 bits. You cannot stuff 32 bits into 8. The compiler gives a warning here about possible loss of data. You can do a cast but all that does is shut off the warning. 32 bits still cannot be packed into 8.
BTW: is was just this situation in the guidance software of a French Ariadne satellite missile that caused it to dump into the ocean for a multi-million dollar loss.
You can convert little things into big things. float to double is OK but double to float is not.
char to short is OK. short to int is OK. int to long is OK. But not the other way around because of possible data loss.
int to float is bad news. Only 6 significant figures in a float leading to loss of data again.
float to int is never OK. double to int is never OK. All the decimals get chopped off leading to loss of data. The compiler warns about this and you have to do cast to shut the warning off.
float to double is OK but double to float is not. double is big while float is small. Loss of data again.Comment
-
Could it be, that you're trying to create a string from an integer value by any chance? (So something like int value = 42 to char* answer = "42"?) If so, you can safely convert ints to chars digit by digit and then save that to a string.
@weaknessforcat s: You are bringing out the big guns with that reply, aren't you? :-DComment
Comment