Skip to content

Latest commit

 

History

History
26 lines (18 loc) · 567 Bytes

File metadata and controls

26 lines (18 loc) · 567 Bytes

Conversion from Integers

An int can represent more values than a char, so conversion from int to char requires the use of the cast operator (char).

~void main() {
int x = 120;

char xAsChar = (char) x;

IO.println(xAsChar);
~}

This conversion is narrowing, so information might be lost if the int value is too big or too small to fit into a char.

The initial value of a char can also be given by an integer literal if the integer literal represents a small enough letter.

~void main() {
char z = 122;

IO.println(z);
~}