Thread: Whats the difference?

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    63

    Cool 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;

  2. #2
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    Google is your friend.
    The world is waiting. I must leave you now.

  3. #3
    Registered User
    Join Date
    Jan 2003
    Posts
    115
    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

  4. #4
    Registered User
    Join Date
    Feb 2003
    Posts
    63

    Red face

    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. #5
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    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. #6
    Registered User Cela's Avatar
    Join Date
    Jan 2003
    Posts
    362
    >>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*

  7. #7
    Registered User zahid's Avatar
    Join Date
    Aug 2001
    Posts
    531
    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.

  8. #8
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    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.
    Last edited by quzah; 02-06-2003 at 12:13 AM.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Review required for program of date difference
    By chottachatri in forum C Programming
    Replies: 6
    Last Post: 10-31-2008, 11:46 AM
  2. Difference Equations / Recurrence Relations
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 10-05-2007, 10:26 AM
  3. What's the difference between var++ and ++var
    By ulillillia in forum C Programming
    Replies: 6
    Last Post: 05-31-2007, 02:27 AM
  4. how to get difference of digits
    By Leeman_s in forum C++ Programming
    Replies: 5
    Last Post: 12-20-2001, 08:32 PM
  5. What is the Difference between ANSI C and non-ANSI C ?
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 11-24-2001, 06:55 AM