What's the difference between these 2 lines, can someone please explain for a beginner...
unsigned int a = 0;
int a = 0;
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 ...
What's the difference between these 2 lines, can someone please explain for a beginner...
unsigned int a = 0;
int a = 0;
Google is your friend.
The world is waiting. I must leave you now.
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.
there are only 10 people in the world, those who know binary and those who dont
Thanks :-)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 bitsOriginally 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.
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" */
>>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 :-)
*Cela*
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).
[ Never code before desk work ]
-------------------------------------:-->
A man who fears Nothing is the man who Loves Nothing
If you Love Nothing, what joy is there in your life.
=------------------------------------------------------= - I may be wrong.
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.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.
[edit to fix horrible line wrapping]
Quzah.
Last edited by quzah; 02-06-2003 at 12:13 AM.
Hope is the first step on the road to disappointment.