Signed Vs Unsigned
By default, if we're just doing
int a = 1;
This will automatically be signed
integer.
We can declare unsigned
by using:
unsigned int a = 1;
unsigned
can store double the value of positive signed integer. For example:
int
values are from-2,147,483,648
to2,147,483,647
unsigned int
are from0
to4,294,967,295
int main() {
int a = 2147483647;
unsigned int unsignedA = 2147483647;
printf("a is %d, unsigned_a is %u\n", a + 1, unsignedA + 1);
}
a is -2147483648, unsigned_a is 2147483648
Printing signed
vs unsigned
Use Printf format type, for
signed
, we use%d
forint
,%l
forlong
unsigned
we use%u
forint
,%lu
forlong
[!note]
If you printunsigned
using%d
, it's not going to present it true value.