getchar() returns an int.
Originally Posted by linuxdude
If you press the key '2', getchar() returns an int with value 50 decimal.
In the C language, the notation '2' indicates a "character constant" whose value is the ascii representation of '2', which happens to be 0x32, or decimal 50.
If you set a char equal to an int, the conversion is made automatically in C by chopping off the upper bits. Since the upper bits of 50 decimal are all zero, the conversion doesn't seem to change anything.
Forgetting getchar() for the moment, try this:
xx = 0x1234;
cc = xx;
printf("xx = %d (decimal), cc = %d (decimal)\n", xx, cc);
printf("xx = %x(hex), cc = %x(hex)\n", xx, cc);