I have the following small snippet where i cast an integer to a char. Afterwards, i cast it back to an int.
The expected result: the integer is 138 What happens: the integer is -118
char arr[10];
int a = 138;
arr[0] = a;
printf("%d", arr[0]);
printf shows -118. The fix that i found is changing the array to an integer array, but I'd like to know why the typecast fails.
This only happens with some integer values. All values upto 127 seem to work just fine.