Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   Signed / Unsigned Conversions (http://www.velocityreviews.com/forums/t805722-signed-unsigned-conversions.html)

Nephi Immortal 11-09-2011 12:06 AM

Signed / Unsigned Conversions
 
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.


All times are GMT. The time now is 10:19 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.