# Integers, signed and unsigned

Sometimes, we know in advance that the value stored in a given integer variable will always be positiveâ€”when it is being used to only count things, for example. In such a case we can declare the variable to be unsigned, as in,

```unsigned int num_students ;
```

With such a declaration, the range of permissible integer values (for a 32-bit OS) will shift from the range -2147483648 to +2147483647 to the range 0 to 4294967295. Thus, declaring an integer as unsigned almost doubles the size of the largest possible value that it can otherwise take. This so happens because on declaring the integer as unsigned, the left-most bit is now free and is not used to store the sign of the number. Note that an unsigned integer still occupies two bytes. This is how an unsigned integer can be declared:

```unsigned int i ;
unsigned i ;
```

#### Example

```#include <stdio.h>
#include<limits.h> // for INT_MAX and INT_MIN Constants

int main()
{
int a = INT_MAX;
int b = INT_MIN;

unsigned int c = UINT_MAX;

printf("Signed integer max value : %d",a);
printf("\nSigned integer min value : %d",b);
printf("\nUnsigned integer maximum range : %u",c);

getchar();
return 0;

}
```

#### Output

```Signed integer max value : 2147483647
Signed integer min value : -2147483648
Unsigned integer maximum range : 4294967295
```

Like an unsigned int, there also exists a short unsigned int and a long unsigned int. By default a short int is a signed short int and a long int is a signed long int.

Share