# Whats the difference?

This is a discussion on Whats the difference? within the C Programming forums, part of the General Programming Boards category; What's the difference between these 2 lines, can someone please explain for a beginner... unsigned int a = 0; int ...

1. ## Whats the difference?

What's the difference between these 2 lines, can someone please explain for a beginner...

unsigned int a = 0;
int a = 0;

3. well int is 32 bits in size and the range of numbers is between
-2,147,483,648 to +2,147,483,647.

whereas unsigned it is only positive range.

4. Originally posted by kurz7
well int is 32 bits in size and the range of numbers is between
-2,147,483,648 to +2,147,483,647.

whereas unsigned it is only positive range.
Thanks :-)

5. Originally posted by kurz7
well int is 32 bits in size and the range of numbers is between
-2,147,483,648 to +2,147,483,647.

whereas unsigned it is only positive range.
int can be 32 bits

From limits.h on my system:
Code:
```#define INT_MIN         (-2147483647-1) /* min value of an "int" */
#define INT_MAX         2147483647      /* max value of an "int" */
#define UINT_MAX        4294967295U     /* max value of an "unsigned int" */```

6. >>unsigned int a = 0;
a can hold any positive value that fits in the number of bits allocated to an int.

>>int a = 0;
a can hold any negative or positive value that fits in the number of bits allocated to an int. Because negatives are allowed, the positive range is halved.

>>well int is 32 bits in size and the range of numbers is between
Maybe for you, but giving exact numbers for something like the size of ints is wrong. Different machines will have different sizes :-)

7. Code:
```Consider int size is 32 bits:
int a = -2147483648;           /* Minimum value*/
int a = 2147483647;            /* Maximum value*/

Consider int size is 16 bits:
int a = -65536;           /* Minimum value*/
int a = 65535;            /* Maximum value*/

it can hold any negative or positive value that fits in the number of bits allocated to an int. Because negatives are allowed, the positive range is halved.

Consider int size is 32 bits:
unsigned int a1 = 0;               /* Minimum Value*/
unsigned int a2 = 4294967295;  /* Maximum value*/

Consider int size is 16 bits:
unsigned int a1 = 0;           /* Minimum Value*/
unsigned int a2 = 131071;  /* Maximum value*/

An unsigned int variable can hold any positive value that fits in the number of bits allocated to an int.

Size of int depends on your File System. Well int is 32 bits in size when you are in Windows, Linux, 16 bits when you are in DOS (I guess)

2*2*2*...(16 times).
2*2*2*...(32 times).```

8. Originally posted by zahid
Code:
```Consider int size is 16 bits:
int a = -65536;           /* Minimum value*/
int a = 65535;            /* Maximum value*/

it can hold any negative or positive value
that fits in the number of bits allocated to
an int. Because negatives are allowed,
the positive range is halved.```
This is wrong. A signed 16 bit integer has 15 "usable" bits and one signed bit. As such, this is wrong. You end up with 32768.

[edit to fix horrible line wrapping]

Quzah.