Forum 2005-2010 (read only)
Syntax & Programs
Topic: type conversions
(Read 2265 times)
Mar 02, 2008, 03:36 pm
How do i preform type conversions? for example converting an int to char?
Re: type conversions
Mar 02, 2008, 03:57 pm
: Mar 02, 2008, 04:02 pm by mem
is done in C by casting as follows:
int i = 64;
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.