N
Nephi Immortal
I read C++ Primer 4th edition book. I look the topic: 5.12.2. The
Arithmetic Conversions
I create three variables to do arithmetic. Some variables have mixed
signed type and unsigned type.
signed char a = 1;
signed char b = 2;
signed char c = a + b;
All variables are signed type. No cast conversion is needed.
unsigned char a = 1;
signed char b = 2;
signed char c = a + b;
The variable a is unsigned type and the variable b is signed type.
Is b converted from signed type to unsigned type before it is added to
a? The variable a is converted from unsigned type to signed type and
store it into variable c. Correct?
signed char a = 1;
signed char b = 2;
unsigned char c = a + b;
Both variable a and b do not need casting conversion because they are
signed type. After addition is done, a is converted from signed type
to unsigned type before stores into variable c.
Arithmetic Conversions
I create three variables to do arithmetic. Some variables have mixed
signed type and unsigned type.
signed char a = 1;
signed char b = 2;
signed char c = a + b;
All variables are signed type. No cast conversion is needed.
unsigned char a = 1;
signed char b = 2;
signed char c = a + b;
The variable a is unsigned type and the variable b is signed type.
Is b converted from signed type to unsigned type before it is added to
a? The variable a is converted from unsigned type to signed type and
store it into variable c. Correct?
signed char a = 1;
signed char b = 2;
unsigned char c = a + b;
Both variable a and b do not need casting conversion because they are
signed type. After addition is done, a is converted from signed type
to unsigned type before stores into variable c.