Go Down

Topic: type conversions (Read 2829 times) previous topic - next topic


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


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