Go Down

Topic: type conversions (Read 1 time) previous topic - next topic

phill

How do i preform type conversions? for example converting an int to char?

mem

#1
Mar 02, 2008, 03:57 pm Last Edit: Mar 02, 2008, 04:02 pm by mem Reason: 1
is done in  C by casting as follows:

int i = 64;
char c;

c = (char)i;   // (char) casts the variable i to a char


casting can have unexpected side affects because the value after the cast may not fit in the variable it is cast to. For example if the int i was equal to 256 before the cast, the char won't be equal to that after the cast because the maximum value for a char is 255.

Go Up