Hi,
is an unsigned integral type negative, and a signed integral type positive? Or is it the exact opposite? There was some confusion on which is which in the book I'm reading.
Hi,
is an unsigned integral type negative, and a signed integral type positive? Or is it the exact opposite? There was some confusion on which is which in the book I'm reading.
Last edited by Programmer_P; 12-22-2009 at 01:10 PM.
unsigned implies that the possible values are non-negative; signed implies that the possible values can be negative.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Note that the MSB of the signed value is used to define if the value is negative or positive, also the value stored for signed types is cut in half to those values stored in an unsigned storage type. Food for thought.
Ok, thanks. One more question:
Are all basic types, such as int, char, etc. signed by default?
No. short int, int and long int are indeed signed integer types, but whether char is signed or unsigned is implementation defined. Consequently, if you want a signed char, use a signed char.Originally Posted by Programmer_P
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)