Typical Ranges of Data Types

Hi all...first post!

I'm reading C++: A Beginner's Guide by Herb Schildt and so far it seems a very good book. However, I'm wondering whether there is an error with the table showing data types and their typical ranges (page 46 if anybody has the book, 2nd edition).

The table lists the following types and ranges:
char -128 to 127
unsigned char 0 to 255
signed char -128 to 127

This seems right to me, as a signed type can be positive or negative, whereas an unsigned type can only be positive.

However, the next six lines are as follows:
int -2,147,483,648 to 2,147,483,647
unsigned int -2,147,483,648 to 2,147,483,647
signed int 0 to 4,294,967,295

short int -32,768 to 32,767
unsigned short int -32,768 to 32,767
signed short int 0 to 65,535

So my question is this:
In the table above, are unsigned int and signed int the wrong way around?
And are unsigned short int and signed short int the wrong way around?

Should the table not look like this?
char -128 to 127
unsigned char 0 to 255
signed char -128 to 127

int -2,147,483,648 to 2,147,483,647
unsigned int 0 - 4,294,967,295
signed int -2,147,483,648 to 2,147,483,647

short int -32,768 to 32,767
unsigned short int 0 to 65,535
signed short int -32,768 to 32,767

Is that now correct, with all three unsigned types only having positive ranges?

Many thanks in advance,
Ruddo...
Last edited on
Yea, he made a mistake, there was a much shorter way to ask this question
I think the second way is correct ( unsigned startig with 0 and up to the maximum value for all the data types )
Your book seems not to be very accurate because is not shure that for default a numeric type is signed
Thanks both. Umz, I wanted to ensure I included all details and the question made sense, but you're right, it could have been more concise.

Bazzy, do you mean that a short int is the same as a signed short int? If so, he does say this, but I guess he included both lines for completeness's sake. Maybe I picked up the habit from him of including more information than is necessary ;-)

Cheers...
It should be the system choosing wether an int is signed or unsigned ( of course is more likely to be signed but if it was shure the keyword signed wouldn't had been created )
It should be the system choosing wether an int is signed or unsigned


Never just let the system 'choose' the type for you, sometimes you need to be specific so its the programmer who decides whether ints are signed or not. The default for char is unsigned.
The default for char is unsigned.|

Not according to *my* copy of the standard...
Topic archived. No new replies allowed.