Thread: difrence between int and long

  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    161

    difrence between int and long

    what is the deference between int and long? I used sizeof() to check and they are the same in bytes.

    Thanx in advance!

  2. #2
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    How big each type is depends on the system it is being run on. C++ guarantees only the following:

    sizeof(short) <= sizeof(int) <= sizeof(long)
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  3. #3
    Registered User
    Join Date
    Nov 2003
    Posts
    66
    My book says that long is suppose to take up twice the size of int (8 to 4) . int can store numbers from -2147486648 to +2147486648 while long can store numbers from -9223372036854775808 to +9223372036854775808. However, the book also noted that the size of each variable form is determined by the compiler's developers.
    An Unofficial Cristiano Ronaldo Website : Ronaldo 7

  4. #4
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Right... C++ doesn't guarantee the exact size of anything, not even the number of bits in a byte. So, it depends on the compiler, and the system in which you are compiling. Many old Windows compilers had 16-bit ints and 32-bit longs. Now, on many Windows compilers, both are 32-bits. Often, it also has to do with the size of the registers in your compiler.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  5. #5
    Registered User
    Join Date
    Jun 2003
    Posts
    361
    You can also get numbers larger than those by using "unsigned"

    This means that the range of numbers stays the same (I.e.):
    -2147486648 to +2147486648 is a range of 4323273296 numbers.

    "unsigned" tells it to ignore the negatives and begin counting at 0.

    So, in the case of the above example:
    "unsigned int X" would hold values from 0 to 4323273296.

    But the range, again, depends on the compiler.

  6. #6
    Registered User
    Join Date
    Sep 2003
    Posts
    135
    Originally posted by Zach L.
    How big each type is depends on the system it is being run on. C++ guarantees only the following:

    sizeof(short) <= sizeof(int) <= sizeof(long)
    Absolutely. In addition, it does guarantee the minimum sizes. A short int and a 'plain' int will be at least 16 bits (-32767 to 32767), a long int will be at least 32 bits (-2147483647 to 2147483647).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  2. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 09:42 PM
  3. Half-life SDK, where are the constants?
    By bennyandthejets in forum Game Programming
    Replies: 29
    Last Post: 08-25-2003, 11:58 AM
  4. How do you search & sort an array?
    By sketchit in forum C Programming
    Replies: 30
    Last Post: 11-03-2001, 04:26 PM
  5. A Simple (?) Problem
    By Unregistered in forum C++ Programming
    Replies: 8
    Last Post: 10-12-2001, 04:28 AM