Go Down

Topic: type conversions (Read 1 time) 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

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131