Can someone explain me how is this at the end
a=?,b=?,c=-124
and not
a=?,b=?,c=132
This is code:
#include <stdio.h>
int main() {
char a = 'D', b='C', c='A';
a = c + 'D';
b = a + b + 'A';
c = b - a;
a = a - b + 'C';
b = b - 68;
printf("a=%c,b=%c,c=%d", a, b, c);
}
Your C implementation has a signed eight-bit
char, likely uses ASCII, and, when converting an out-of-range value to a signed integer type, wraps modulo 2w, where w is the width of (number of bits in) the type. These are all implementation-defined; they may differ in other C implementations, with certain constraints.char a = 'D', b='C', c='A';initializesato 68,bto 67, andcto 65.a = c + 'D';assigns 65 + 68 = 133 toa. Since 133 does not fit inchar, it wraps to 133 − 256 = −123.b = a + b + 'A';assigns −123 + 67 + 65 = 9 tob.c = b - a;assigns 9 − −123 = 132 toc. This wraps to 132 − 256 = −124.a = a - b + 'C';assigns −123 − 9 + 67 = −65 toa.b = b - 68;assigns 9 − 68 = −59 tob.printf("a=%c,b=%c,c=%d", a, b, c);printsa=?,b=?,c=-124becauseaandbare codes for abnormal characters and the value ofcis −124.