I understand what signed
and unsigned int
means.But a signed char
doesn't make any sense to me.
Also why both signed and unsigned int
occupies the same amount of space. Signed int
should occupy more space since it can contain both negative and positive numbers.
Thanks in advance.
Asked
Active
Viewed 1.0k times
1

Jeyaram
- 9,158
- 7
- 41
- 63

user239321
- 47
- 1
- 1
- 6
-
About the integer question, it's all about the range of numbers. Check the ranges of Signed and unsigned int. – Bibhas Debnath Feb 04 '14 at 06:01
-
1char doesn't mean a letter, it means 1 byte integer and it is signed by default. – perreal Feb 04 '14 at 06:02
-
`signed char` represents −128 ~ 127. `unsigned char` represents 0 ~ 255. `signed int` represents −2,147,483,648 ~ 2,147,483,647 and `unsigned int` represents 0 ~ 4,294,967,295 for usual Windows (XP/7/8) system (in Microsoft Visual Studio 20xx). They are the same size of numbers, right? – Naetmul Feb 04 '14 at 06:05
1 Answers
0
The sign takes up one bit.
So an unsigned char can have values 0 to 255 and a signed char has values -128 to 127.
So signed and unsigned are the same number of bits, can have the same number of values, but signed values can represent negatives values, but not as many positive values.

Loe
- 327
- 2
- 5
-
2The actual ranges differ in places where `CHAR_BIT` is greater than 8 and/or negative numbers are not represented in two's complement. – Brave Sir Robin Feb 04 '14 at 06:06