In my textbook, it says that all integers are considered signed by default, and most of the sources I've found online say that floating point numbers have to be signed, so what's the point of using the signed
keyword?

- 11
- 1
-
3You might use it for `char` variables, which are [not specified to be either signed or unsigned by default](http://stackoverflow.com/questions/2054939/is-char-signed-or-unsigned-by-default). – Paul Rooney Feb 16 '17 at 02:05
3 Answers
In C, you can omit parts of a typename, so you can actually use signed
instead of int
, which may look nicely symmetric:
void f(signed a, unsigned b);
Or more verbosely:
unsigned int foo;
signed int bar;
If you don't use both types in close vicinity, you would probably prefer the simpler form of the name:
int x; // normal
auto y; // quaint
signed auto graph; // why not

- 464,522
- 92
- 875
- 1,084
At least two situations exist where the keyword unsigned
is needed.
The first one is using the keyword with the type specifier char
because it can behave either as signed char
or as unsigned char
. That is there are three distinct types: char
, signed char
and unsigned char
.
The second one is using the keyword with bit fields because a bit field with the type specifier int
can behave either as signed int
or as unsigned int
.

- 301,070
- 26
- 186
- 335
-
C11 sounds like a plain `int` would not be allowed portably as the type of a bit field (6.7.2.1/5). – Kerrek SB Feb 16 '17 at 02:17
-
@KerrekSB There is written that "for bitfields, it is implementation-defined whether the specifier int designates the same type as signed int or the same type as unsigned int." – Vlad from Moscow Feb 16 '17 at 02:26
the signed
word isnt get used so much.
the unsigned
does because all the integer-types(char is worth-checking)
are self-defined as signed. also, unsigned float
, unsigned double
or
unsigned long double
do not exist.//signed float/double/long double are errors to.

- 769
- 8
- 25