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:
intvalues are from-2,147,483,648to2,147,483,647unsigned intare from0to4,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%dforint,%lforlongunsignedwe use%uforint,%luforlong
[!note]
If you printunsignedusing%d, it's not going to present it true value.