Thread: data type limits

  1. #1
    Registered User JTtheCPPgod's Avatar
    Join Date
    Dec 2001
    Posts
    44

    data type limits

    Can anyone tell me the upper and lower limits for the basic data types (int, float, long, etc.)?
    ie. Ints have upper limits of 32000ish if I'm not mistaken, but I need the exact numbers.
    Thanks a bunch...

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Look in limits.h
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Registered User JTtheCPPgod's Avatar
    Join Date
    Dec 2001
    Posts
    44

    um

    That didn't seem to work.
    I'm not terribly advanced and I have trouble reading what the libraries say.
    And it also didn't look like it had all the data types I needed (if it did, they had different names)
    anybody else?
    "No! I must have my delicious cupcakes, my sweet cakey treasures, piping hot from their 40 watt WOMB!!!"
    --Captain Murphy

  4. #4
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    Look in either <limits> or <limits.h>
    Here's an example using limits:

    Code:
    #include <iostream>
    #include <limits>
    
    int main(int argc, char** argv)
    {
       using namespace std;
       cout << "\nsigned int max: " << std::numeric_limits<signed int>::max();
       cout << "\nsigned int min: " << std::numeric_limits<signed int>::min();
    
       cout << "\nchar max:  " << std::numeric_limits<char>::max();
       cout << "\nchar min: " << std::numeric_limits<char>::min();
    
       return 0;
    }

  5. #5
    Registered User JTtheCPPgod's Avatar
    Join Date
    Dec 2001
    Posts
    44
    I'm afraid I still don't understand.
    I don't want a program that produces these values.
    I don't even have a copy of Visual Studio herea t home.
    I just need the numbers...
    "No! I must have my delicious cupcakes, my sweet cakey treasures, piping hot from their 40 watt WOMB!!!"
    --Captain Murphy

  6. #6
    Registered User Cela's Avatar
    Join Date
    Jan 2003
    Posts
    362
    >>I just need the numbers...
    The numbers will be different for different machines. You have to use either <limits> or <climits>/<limits.h> for any measure of portability. If anyone gives you just the numbers and doesn't say "at least" then they're wrong. :-)
    *Cela*

  7. #7
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    It's implementation dependant.
    Depending on what system you're on, the size of different types vary.
    edit: Beaten

  8. #8
    Registered User nag's Avatar
    Join Date
    May 2002
    Posts
    22
    For a 16 bit machine it is

    unsigned int=2^16 -1 (2 to the power 16) =65535

    for a 32 bit machine

    unsigned int=2^32 -1 =4294967295

    for signed int value divide it by two
    at the moment my calculkator is not working
    Last edited by nag; 01-27-2003 at 08:20 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Replies: 0
    Last Post: 03-20-2008, 07:59 AM
  3. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  4. HUGE fps jump
    By DavidP in forum Game Programming
    Replies: 23
    Last Post: 07-01-2004, 10:36 AM
  5. C diamonds and perls :°)
    By Carlos in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 05-16-2003, 10:19 PM