+ 1
How to convert int type to char type
2 Answers
+ 11
You can convert an int type simply by assigning to a char.
int c = 97;
char a = c;
0
I think that's an implicit cast...
char b = 'B';
int i = b;
... should compile with a moan if -Wall was passed to the compiler. OTOH...
char b = 'B';
int x = (int) b;
int y = int(b);
... Will definitely work fine since it's explicitly cast.
Note: the "char" type is an 8-bit int. Thus you can get away with implicit casting with only compiler warnings. I recommend explicit casting (second example) nonetheless because it makes code more readable.